SVN Cheat Sheet

Incidently, our svn server is https://alis.cs.bath.ac.uk/svn/bai/

getting started

Here's the manual.   svn vs cvs quick comparisonsvn gui discussion.

If you use a different user name on your server than on the computer you are calling it from, you need the flag --username [me] right after svn.

Commands

Info commands

This directory is under version control - Tell me about the code?
svn info
Lists the repository URL (see below), the checked out revision number etc.

What's available on the repository server?
svn list URL
URL is something like http://myhost.com:/svn-repos, where svn-repos is the path to the repository on the server, assuming you're serving svn via Apache.  This lists the top level directories.

Who's done what lately?
svn log
Lists the commit comments (in reverse order).

Major high-level svn acts

Check out the directory 'Module'
svn checkout URL/Module
Note: This does not lock Module.  Others may do the same as you and cheerfully make inconsistent changes.  These are resolved by one or other of you on commit.

Check out directory Module but call it MyModule
svn checkout URL/Module MyModule

Get directory Module out for distribution, not for editing
svn export URL/Module ModuleReleaseName

Update your checked out copy to the latest version (pull latest version from the server).
svn update
Note: this only updates files at or beneath your current directory level.

Commit your changes (send your changes to the server for others to see).
svn commit [files to commit] [-m 'my message']
Leaving out the message means the value of shell variable SVN_EDITOR will pop up for your message (or the system's default editor).  Leaving out the file list means everything uncommitted is committed.

Resolving conflicts:
See http://svnbook.red-bean.com/en/1.1/svn-book.html#svn-ch-3-sect-5.4

Tagging a release (e.g. for putting on a web page.)
svn copy URL/Module URL/Module/tags/release-1.0/ [-m '1.0 release']
Note this assumes tags/ directory exists.  If it does not use 'svn mkdir'.  Note that unlike CVS there is no real tagging built into SVN, this is just a system that works by convention.

Add a new project (with existing files) to a repository.  This will create a new branch in the repository, even with multiple subdirectories.
svn import thisdir URL/newdir
Note that this will not checkout your code for you, thisdir is not put under revision control.  For a controlled version, you need to do a seperate svn checkout.

Making changes to your own copy of the code tree

Note: you may be prompted to do many of these things if you try to commit & haven't done them already, but it's more graceful to remember to do them when you change your directory.

Add a new file to directory
svn add dir/newfile.txt

Move a file from place to place
svn mv oldpos/file.txt newpos/file.txt
Adding a directory will add all its contents.

Copy a file
svn copy oldpos/file.txt newpos/samefile.txt

Remove a file
svn rm [filename]
Note: this removes the local copy for you too.  If you just 'rm' a file without 'svn rm'-ing it, just 'svn rm' it explicitly before you commit.  svn status will flag when this needs to happen.

See what is changed, uncommitted etc.
svn status
Note: this is a cheap operation unrelated to commit. It needs no access to a networked repository.

Examine differences you've made since you got the file from the archive
svn diff dir/newfile.txt
Note: the above needs no access to a networked repository.  If you want to compare to something on the repository (e.g. the current version or previous ones), see svn help diff for details.  You may actually want to use svn merge, because that takes into account the history of files whose names have changed.

Revert the file contents to the repository version because your changes suck.
svn revert dir/newfile.txt
Note: This also undeletes things (assuming you used 'svn rm'). 



Admin Stuff

Make a new repository (On the server)
svnadmin create /usr/local/svn-repos
This creates a Berkley DB backed subversion repository.  To get a file system based on, use the '--fs-type fsfs' flag.
This only needs to be done once, and has probably already been done for you!  (Certainly if you are using BAI)

Once your server is set up, but you have an empty repository, you want to do this:

  1. Create a folder on the server for your project.
  2. Create inside that branches, tags & trunk (three folders.)
  3. Checkout the empty trunk directory.
  4. Copy the files you want to put on the server into the new directory.
  5. Do a commit!
Why?  BDB-backed repositories will not work over NFS/AFS/Samba.  But that should not matter since you should have set it up to run on a server and be accessed by Apache.  BDB is a database, and can therefore get wedged after certain interruptions.  You can use 'svnadmin recover' to sort some things out.  Using a file system backed repository ducks all these problems.

Dump, archive and reload a repository
svnadmin dump URL/svn-repos > svn-repos-dumpfile

svnadmin hotcopy (same as dump only safer)
svn load /usr/local/new-repos < svn-repos-dumpfile

Will Lowe - 24 July 2005
Modified by Joanna Bryson 27 Jan 2006