Useful Subversion commands

From GridInfo

Jump to: navigation, search

Contents

Subversion

The latest version of Subversion (December 2006) is 1.4.2. It is available as a pre-compiled binary for most popular systems, including several flavours of Linux (e.g Debian, Red Hat, Fedora Core), as well as Windows and Mac OS X.

Installing Subversion on a Debian System

The Subversion package for Debian systems, at version 1.1.4 for the Debian Sarge (stable) branch of the OS, and at version 1.4.2 in the Etch (testing) branch, is very easy to install.

 $ sudo apt-get update
 $ sudo apt-get install subversion

Installing on Mac OS X

Pre-built and packaged binaries can be downloaded from http://metissian.com/projects/macosx/subversion/. A couple of double-clicks, first on the downloaded image and then on the installer file, and you are done.

You can also download the svnup Subversion client GUI from the same web page at metissian.com. Svnup comes with some other stuff for use with Metissian's commercial Java IDE (IDEA), but works without it. Download svn4idea45 and open the image - locate a file called something like svnup-0.9.2.jar and save it to a convenient place (like Applications).

Useful Subversion commands

Check out a project from the repository

$ svn checkout file:///path/to/repos/trunk project
A project/file1
A project/file2
…
Checked out revision 1.
  • This gives you a personal copy of part of the repository in a new directory called (in this case) "project".
  • You can edit these files without affecting the repository. Changes are made to the repository only when you commit these files back to it.

Commit changes to the repository

$ svn commit -m "added print section"
  • If you do not supply a log message ("added print section" in this case), Subversion will launch an editor for you to enter one. A message is expected, a good idea, and, ideally, should still mean something in 6 months time.

Working with the working copy

  • You can work with files in your working copy just as you would with other files in your system, but if you want changes to be reflected in the repository you must use subversion commands rather than system commands to perform some actions. For example, use svn move and svn copy to move or copy files rather than your system's normal commands, and use svn add and svn delete to add or delete files.

Updating the working copy

  • To update your working copy so that it picks up changes to the repository since you last updated.
$ svn update
  • This does NOT erase changes you have made. Different versions of a file are merged if changes by two users are in different parts of the file. If there is a conflict, Subversion will alert you. Your changes do not reach the repository until you commit them.

Checking what you have done

  • To see what file and hierarchy changes you have made (compared to the version after your last update - NOT compared to the repository as it is now).
$ svn status
  • To see the actual changes you have made (this command without any switches or parameters will show you the diffs between the last update and your current versions for every file).
$ svn diff
  • To undo changes for a particular file
$ svn revert <filename>
  • Note that svn revert can undo changes such as svn add, svn delete, as well as edits to the contents of a file.

Typical work pattern

Subversion links

Personal tools