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.



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

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

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:

Adding or Removing Files for Version Control

svn add PATH       # add PATH to 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:
The labels U and G denote clean updates, U meaning that the item was not modified locally by you but was updated from the repo, and G meaning that the changes from the repo do not conflict with your changes. The item which might catch your attention is C, which means there's a conflict somewhere. If you get this, then you must resolve the conflicts before you commit your own changes. In fact, you might find that Subversion won't even let you commit before fixing these issues.

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:
  1. <filename>.mine: This is your local working copy.
  2. <filename>.r[OLDREV]: This is the version you checked out before you made the changes that led to your local working copy.
  3. <filename>.r[NEWREV]: This is the latest version from the repository.

To resolve the conflict, you must do one of three things:
  1. Use "svn revert <filename>" to throw away your local changes.
  2. Copy one of the three temporary files over conflicting file.
  3. 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
Computer Science @ George Mason University