Subversion Basics (svn tutorial)

Perm url with updates:

SubVersion (svn) Tutorial

Xah Lee, 2009-08-28, 2010-08-10

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://
svn checkout svn://
svn checkout 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 -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 a file or dir, use the add command:

svn add ‹file/dir name›

To remove a file or dir, use the rm command first. Then, svn will delete the file or dir for you. Do not delete the file/dir yourself.

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 .

Updating won't erase changes you made. When there's a conflict, svn will tell you.

How to erase your local edits?

If you made some changes (and have not committed yet), 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 “”, and the current version is 161, you want the version 107. These are the commands you need to run:

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

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

How to find which files changed on your disk?

svn status .

For explanation of the output, see: “svn help status”.

Creating Projects

Here are some tips for svn admins.

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/mysourcecode file:///usr/local/svn_rooty -m "Initial import of my lovely project"

The path “/Users/xahlee/mysourcecode” is the path of your source code folder, the “file:///usr/local/svn_rooty” is a path for the svn root path, in a url format. The “-m” is a comment.

Then, modify the file


To contain for example these lines:


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:

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

What should be the file permissions?

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


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 “--listen-port=3091” can be omitted. The default port for svn is 3690.

Once you did this, a client can checkout with these commands:

svn checkout svn://
svn checkout svn://

# if using default port
svn checkout svn://

Importing Your Source Code Into Google Code

If you host your project at Google Code, they have svn built-in. Here's instruction on how to import your source code dir into google code. (we assume that your source code dir is brand new, and is not already under a svn.)

By default, a svn repository is created for you as soon as you filled out the form for a google code project.

Now, you need to do a svn checkout, even though there's nothing to check out. The purpose to checkout is to create those svn internal files on youl local disk.

To checkout, first create a dir on your local disk where you want the local mirror to be. Then, cd to the dir, then do:

svn checkout xyz --username xahlee

Once you have checked out, you'll see that your current dir has a “.svn” dir. That's svn's internal files.

Stay in the dir. Now, you can use the “import” command to actually create stuff in your svn repository at google code.

Suppose your source code dir is at “c:/Users/xah/xyz”. You want to import this dir to google code's svn. Type the following in your command line:

svn import "c:/Users/xah/xyz" -m"first import of the project."

Popular posts from this blog

11 Years of Writing About Emacs

does md5 creates more randomness?

Google Code shutting down, future of ErgoEmacs