Subversion Primer
Subversion is a free, open source, version control tool. To access it, you need to have the Subversion client installed. On most modern Linux distributions, this package is also available through yum, apt, or portage under the name subversion.
SVN GUI Tools
There are several graphical tools to access and manipulate SVN repositories. These can help those people who are not yet fully familiar with version control through CVS or SVN. However, it is strongly suggested that you go through the Subversion Quick Start guide below and familiarize yourself with console operation of SVN. Note: Many of these graphical tools will still require that you have the Subversion client installed.
- RapidSVN - Cross-platform C++ GUI for SVN. Also available through Yum or Apt in most modern Linux distributions as rapidsvn. Based on wxWidgets, it runs on Mac OS X, Linux, Windows, Solaris, etc.
- TortoiseSVN - Windows GUI for SVN. Excellent shell integration makes this one perhaps the best Windows SVN client around.
- SCPlugin - Mac OS X Finder plugin for Subversion. Inspired by the popular TortoiseSVN client.
- SvnX - A Mac OS X native client for SVN.
- Subclipse - Eclipse integration for SVN.
Subversion Quick Start (Using the Console)
This guide outlines the basic day-to-day work flow in Subversion. Also check out the O'Reilly Subversion Book, and the Subversion online documentation for more details. You can also type "svn help [command]" to get instant help on a particular command.
Checkout
This operation downloads a working copy of the source code. In most cases, you will only have to run this command once to get started.
svn co https://vo.homelinux.org/svn/icpc icpc --username icpc
cd icpc
cd icpc
Updating and Reverting
The update command synchronizes your local working copy with changes that have been committed to the source code repo, except for files that you have edited locally. Doing the update command is recommended as often as possible. To do this, go to the root of your local working copy and use the command:
svn update
To revert to the last updated version of a file or directory, discarding any changes you've made locally, use the revert command on the path to that file or directory. You don't need internet access to do this:
svn revert PATH
To replace a file with the latest version from the repo, discarding any changes you've made:
svn revert
svn update
svn update
Examining History and More Information
svn log # broad information, including list of changes w/ comments svn diff # differences between local files and last updated version. svn cat # show the contents of a file for a particular revision number. svn list # list the contents of a path.
A particularly useful command is status, which will give you the status of items in your local working copy.
svn status # get the status of your local copy.
The first column of status output contains some letters which have the following meanings:
- A item - The file named item is scheduled for addition to the repo on next commit.
- C item - The file named item is currently in a state of conflict.
- D item - The file named item is scheduled for deletion on next commit.
- M item - The contents of file item have been modified locally.
Adding or Removing Files for Version Control
svn add PATH # add PATH to version control
svn remove PATH # remove PATH from version control
svn remove PATH # remove PATH from version control
Items marked with add or remove will be scheduled for addition or deletion from your local copy as well.
Move or rename a file under source control
svn mv OLD_FILENAME NEW_FILENAME
How to Resolve Conflicts
First, do an update command to get the latest changes in the repo:
svn update
The first column of the output be characters preceding the filenames to indicate the update action taken. The meaning of each of the characters is:
- A Added
- D Deleted
- U Updated
- C Conflict
- G Merged
For each conflicted file, for example <filename>, Subversion puts conflict markers in <filename> to help you identify the error, and then gives you three additional temporary files to help you resolve your differences:
- <filename>.mine: This is your local working copy.
- <filename>.r[OLDREV]: This is the version you checked out before you made the changes that led to your local working copy.
- <filename>.r[NEWREV]: This is the latest version from the repository.
To resolve the conflict, you must do one of three things:
- Use "svn revert <filename>" to throw away your local changes.
- Copy one of the three temporary files over conflicting file.
- Directly edit the file and merge the conflicts by examining the conflict markers Subversion inserted, and manually making the desired changes.
Once you have resolved those conflicts, then tell SVN that there are no more conflicts with the file:
svn resolved <filename>
Committing your changes
svn update # [if there are items marked "C" then resolve conflicts (see above section)] svn commit
List of MASC Resource Pages