Short Introduction to Subversion

The original version of this Web page was written by Lorenz Froihofer and found on http://www.froihofer.net/en/students/svn-intro.html. Reprint and modification on this Web page with friendly permission of the original author.

On the departmental Linux systems, a number of tools for and GUI interfaces to Subversion are installed: cvs2svn, esvn, latex-svninfo, rapidsvn, kdesvn.

Getting started

The goal of the Subversion project is to build a version control system that is a compelling replacement for CVS in the open source community. [Subversion].

Installation

Subversion can be downloaded from http://subversion.tigris.org/. For Mirosoft Windows, there exists a GUI-Application called TortoiseSVN. This tool integrates into the Windows Explorer and can be used via the context menu (right mouse click). Both Subversion and TortoiseSVN are available with an installer. If you are using Linux, check whether your Linux distribution already provides the subversion-package for you.

Usage

This short introduction to the use of subversion concentrates on the commandline client (svn) of subversion. Please map these information for TortoiseSVN by yourself as the commands are titled mostly the same way in TortoiseSVN's context menu.

Moreover, how to setup and administrate a Subversion repository is only covered very basically ... on repository servers, this is already done for you by the administrators of the server. To setup a new Subversion repository in your home (or some other) directory, use:

    svnadmin create --fs-type fsfs /path/to/repository

When starting to use a repository, the first thing to do is to check-out the repository to your own computer by using the "svn checkout" command. Afterwards, you can start working on the code. A short overview of the most important commands is provided below.

CommandDescription
svn helpLists available svn commands
svn help COMMANDProvides a description of the specified command.
svn checkoutInitial checkout of a svn repository. Typically called in the following way:
  • on machines that have direct access to (the directory containing) the repository by specifing it as:
    (e.g. for repositories in your home directory)

      $ svn checkout file:///path/to/repository DIRECTORY_FOR_CHECKOUT

  • on machines that do not have such direct access by specifing the repository as:
    (e.g. for repositories on a repository server)

      $ svn checkout svn+ssh://user@hostname/path/to/repository DIRECTORY_FOR_CHECKOUT

    where the given machine must of course have direct access to the repository in question.
    If your login name on the machine in question is the same as on the machine you use the svn tools, you can leave out the user@ part.
The DIRECTORY_FOR_CHECKOUT is the name of a local directory on your computer.

Make sure you read the tip about using ssh on the overview page.

svn statusProvides a status overview of the local repository - lists added, modified, deleted and unknown files
svn updateUpdates the local repository to the latest version of the server.
svn add FILE...Adds the specified file(s) to the repository - will be transfered to the server at the next time svn commit is called.
svn rm FILE...Removes the specified file(s) from the repository - will be removed from the server the next time svn commit is called.
svn mv FROM TORenames/relocates a file/directory from FROM to TO.
svn revert FILE...Removes any changes on the specified files performed since the last "svn update" (or "svn checkout").
svn commitCommit in the sources from the local repository to the server.
Please follow the principles provided below for commiting to the repository:
  • Specify an appropriate log message every time you commit so that other developers know what you have changed.
  • Before you commit resources into a repository, run "svn update" and check whether everything still works as expected, e.g. run "ant clean dist test" to cleanly compile your sources and check whether the test cases execute without errors.
svn diffDisplay the differences between two versions - the modifications since the last "svn update" by default.
svn cleanupRecursively cleans up the working copy, removing locks, resuming unfinished operations, etc. Call this if requested by the output of another svn command or if you are uncertain whether your working copy is clean.

For further details on subversion see the book Version Control with Subversion or the FAQ.

Important Notes for Version Control

Concurrent Changes

Don't overwrite concurrent changes: If you checked out the sources from a repository, please work on these sources directly. If you proceed the following wrong way:

  1. Check out the sources, e.g. to MY_DIR
  2. Copy the files to some other directory, e.g. OTHER_DIR
  3. Run "svn update" within MY_DIR to bring up your repository to the latest version
  4. Copy your changed sources back from OTHER_DIR to MY_DIR
  5. Run "svn commit" within MY_DIR

concurrent updates, e.g. bugfixes by other developers, will not be detected and at some point in time you will certainly overwrite concurrent updates of other developers who won't be very happy with the fact that you voided their efforts.

Hence, proceed as follows:

  1. Check out the sources, e.g. to MY_DIR
  2. Modify the sources in place (within MY_DIR or some subdirectory)
  3. Run "svn update" within MY_DIR
  4. If "svn update" reports conflicts, resolve them
  5. Check whether everything compiles again and run "svn commit" within MY_DIR to check in all the changed sources at once.

Undo Changes

If you discover that you committed something wrong (e.g. at revision 305) that should never have been committed and want to undo it, you can perform that by calling "svn merge -r N:M SOURCE [WCPATH]" where N is the revision you wrongly commited and M is the revision before, source may be an URL or working copy item, the WCPATH is a working copy path that may be omitted in which case "." is assumed. For example, you just committed revision 305 and want to undo it. In the easiest case, you just perform "svn merge -r 305:304 ." within the root directory of your development tree. After you verified that this command produced your desired results, you have to svn commit your changes.

If you have not yet commited your changes, you can simply svn revert your local changes (see svn help revert).