HMC Homepage      CS Home

Using Subversion (svn)

A general overview of Subversion and a brief guide for its use


1. About Subversion

1.1 What is Subversion?

Subversion is a version control program intended as a direct replacement for CVS, the concurrent versioning system. It's a new program that fixes several things that were considered broken or awkward in CVS. For more general information about versioning systems, please see the CVS qref.

1.2 How does Subversion differ from CVS?

Subversion is very like CVS. Some useful improvements include the fact that the whole repository gets a new version number each time there is any change, and that you can easily rename or move files around in the repository without losing version information. The changes are detailed more explicitly here.

back to the top


2. Using a repository

2.1 How do I use an existing repository?

To create a working copy so you can make changes to the documents in the repository, you need to check out the directory they are in:

% svn checkout file:///home/user/repos working

This checks out the documents in the /home/user/repos repository and puts them into a folder called working in the current directory. You can then edit these files and check them back in to confirm your changes.

Some repositories are made available via a web sever, in which case file:///... would be replaced by a http://... or https://... URL.

2.2 How do I check my updated files back in to the repository?

First, you will want to check what exactly you have changed using the following command:

% svn status

For a good discussion of status codes, see here. After reviewing the changes you have made, use the following command:

% svn commit -m "Comment about update" If you leave out the -m message, subversion will try to open an editor in which you can create your comment.

2.3 How can I add/rename/duplicate repository files and subdirectories?

% svn add <file>

This command will add a file into the repository and begin storing versioning information for it. (It will appear in the central repository only at the next svn commit) To create another copy of a file or directory already in the repository, use:

% svn copy <oldname> <newname>

To rename (or place in a different directory) a file in the repository, use:

% svn move <oldname> <newname>

2.4 How can I remove files from the repository?

% svn delete <file>

This will remove a file from version control and delete it in your working copy. If the repository contains versioning information for the file, it will remain. (And if you ask subversion for a version of the repository as it was before the deletion, the files will reappear.)

2.5 What if I want to revert to an older version of a file?

% svn revert <filename> will revert to the most recently checked-in version of a file.

2.7 What if I want to specify an older version of a file?

First, you must find out which revision you want. Type:

% svn log <filename>

to view all log entries of checkins in which that file is changed. From there,

% svn co -r <rev> <filename> will revert to revision number <rev> of the file.

2.6 How do I find the differences between versions?

% svn diff <filename>

This command will enumerate each line in your working copy that is different from the version in the repository.

2.7a How do I resolve conflicts?

Resolving conflicts is one of the more confounding aspects of using SVN. Luckily, there is a very good treatment of the subject here. The gist of it is that when the version of a file in the repository and the version in your working copy have overlapping changes, you will not be allowed to check the file back in (it will have a C as its status code).

2.7b What did it do to my file?

In your file, you may find lines composed of '<', '=', or '>' characters with revision numbers (or .mine) after them. These conflict markers designate where your version of the file overlaps with the previous revisions. You should remove these markers as well making the desired changes to the file before attempting to resubmit it.

2.7c How do I get SVN to accept the revision?

% svn resolved <file>

This lets subversion know that you have resolved the conflict. From here, you are free to submit again. Also, you can revert the file and then check back in without having to run svn resolved.

2.8 How do I get rid of the directory that "checkout" created?

You can simply delete the working directory if you no longer need it (after saving your changes, if you want to). If you need another copy, you can just check it out again.

2.9 I want to do something else, but you haven't told me how to do it!

Take a look at Version Control with Subversion. Odds are that if svn can do it, it's in there. Of specific note is the extensive command reference at the back of the book.

back to the top


3. Accessing your repository remotely

3.1 How do I access remote repositories?

If the repository lives on machine that allows you to log in, and if you are running on Unix, Linux, or some variant that has an ssh command, use the following command (substituting appropriate values where obvious):

% svn checkout svn+ssh://server.cs.hmc.edu/your/repository/directory

3.2 What if I want to do this from Windows?

You can use TortoiseSVN to connect to the CS department servers by following the (relatively complicated) instructions given here. Ignore the "Installing Subversion" section, as well as the part about creating a user (just use the .ssh directory in your home directory). Alternatively, you can get a command-line ssh program such as the one from Cygwin, and proceed as in 3.1.

back to the top


4. Establishing a new repository

4.1 How do I create a repository?

Choose somewhere to put it, then run the following command:

% svnadmin create <path>

where path is the path (on the local filesystem) to the repository. This will create a directory containing administrative files at the specified path. Next, you will probably want to add your files to the repository so you can begin editing them.

4.2 How do I put files into the repository?

If you're starting from scratch, you can just get a working copy of the repository (initially empty) and svn add new files and directories as needed (followed by svn commit, of course).

The following command imports the files in a specified project directory into the given repository:

% svn import <project path> <repository path> -m "Initial import"

The -m option allows you to specify a log message. When entering the repository path, you must provide a protocol used for access. For local files, use the "file" protocol. Thus, to import the folder ~/test into the repository in ~/repos with a log message of "starting repos", the following command would be issued:

% svn import ~/test file:///home/<username>/repos -m "starting repos"

back to the top


5. More information

back to the top

Copyright (c) HMC Computer Science Department. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled ``GNU Free Documentation License.''

HMC Computer Science Department
Contact Information
Last Modified Friday, 28-Oct-2005 11:54:44 PDT