If you enjoyed this site, please consider donating $3. Any amount is appreciated. Thanks!

SubVersion Tutorial

Xah Lee, 2009-08-28

This page is a quick start tutorial of using SubVersion (SVN), a version control system.

Basic Check Out, Commit

What commands are available?

Type “svn help”.

How to checkout a project?

cd to a directory where you want the files to be. Then do for example:

svn checkout svn://vmm.math.uci.edu/transvections
svn checkout svn://vmm.math.uci.edu/
svn checkout https://emacs2010.googlecode.com/svn/trunk/ ErgoEmacs --username xahlee

How to commit a change?

Once you checked out, made your modifications, then you can check back in (commit your changes). To commit, cd to the working dir, then do:

# commiting all files in current dir
svn commit . -m "one-line summary of what you changed"

# commit one file
svn commit init.py -m "one-line summary of what you changed"

How to Add or Remove a dir or file?

If you created new files in your working copy and committed it, that won't work. You will need to run a svn command first to add or remove a file or dir, then commit.

To add, use the add command:

svn add ‹file/dir name›

To remove a file or dir, use the rm command first:

svn delete ‹file/dir name›

Once you are done adding or removing, then you need to do a commit.

How to update your working dir?

“cd” to your working dir and use the “svn update” command. Changes made by others will now show in your working copy.

svn update .

How to erase your local edits?

If you made some changes (without commiting), and decided it's all bad, you want a clean copy from the repository. You can revert (and discard all your edits):

svn revert . --force

How to revert to a previous version?

If you want to revert a version to a previous version, here's what to do. Note that there's a “revert” command, but that's not what you want. The “revert” command simply erase your local edits. What you want is actually the “merge” command. (yes, it is very unintuitive)

Suppose you have this file “xyz.ml”, and the current version is 161, you want the version 107. These are the commands you need to run:

svn merge -r161:107 xyz.ml
svn commit -m "Reverted to revision 107." xyz.ml

The “merge” command will change that file on your machine to revision 107. The “commit” actually makes that change back to the central repository.

Creating Projects

How to create a project?

First, create the svn root dir using this command:

sudo svnadmin create /usr/local/svn_rooty

You need do the above. It is not merely creating a dir with “mkdir”.

The “/usr/local/svn_rooty” is the dir you want svn to hold the repository.

To import a project, do:

sudo svn import /Users/xahlee/proj_luv file:///usr/local/svn_rooty -m "Initial import of my lovely project"

the first arg is the path of your folder, the second argument is a url for the svn root path. The “-m” is a comment.

Then, modify the file

/usr/local/svn_rooty/conf/passwd

To contain for example these lines:

[users]
xahlee=xyz
dick=xyz
bob=xzy

The left side is user's login name, the right side is password. This is for running svn as a stand-alone server.

modify the file “/usr/local/svn_rooty/conf/svnserve.conf” to contain these lines:

[general]
anon-access = read
auth-access = write
password-db = passwd
realm = transvections

How to start the stand-alone server?

First, change to svn user.

sudo su svn

Then, run the following command to launch it, while you are “svn” user.

svnserve --daemon --listen-port=3091 --root=/usr/local/svn_rooty 

The “--daemon” is for stand-alone, the “--root=” specifies root, so that in the checkout command it doesn't need to specify the full path.

The default listening port is 3690

What should be the file permissions?

The following dir needs to be owned by “svn” user.

db/
db/revprops
db/revs
db/transactions
db/write-lock
2009-08
© 2009 by Xah Lee.