Open Source

Get to know Subversion as a replacement for CVS

Vincent Danen shows you some of the common commands for using Subversion and gives you an example of setting up a Subversion repository.

Subversion is a version control system similar to CVS, but different in a number of respects that make it more robust and quite a bit better. Subversion is quickly becoming an extremely popular replacement for CVS. (In a previous tip, I showed you how to connect to a subversion repository using an Apache 2 Web Server.)

A lot of the commands are similar to what CVS provides, but they can be different in a few ways. The svn command is the equivalent to the cvs command; and svnadmin is the equivalent to the cvs admin command.

Tips in your inbox
Delivered each Tuesday, TechRepublic's free Linux NetNote provides tips, articles, and other resources to help you hone your Linux skills.
Automatically sign up today!

To create a subversion repository, use:

<code>
$ svnadmin create ~/subversion/repos
</code>

This would create a repository in your home directory in ~/subversion/repos. To add a directory to the repository, use:

<code>
$ svn mkdir file:///home/user/subversion/repos/www
</code>

This would add the directory www to your repository. To add a newly created file to the repository in the www directory, use:

<code>
$ cd ~/subversion/repos/www
$ svn add index.php
$ svn commit
</code>

Then, if you were to make changes to index.php after it was committed, you could view a diff of the changes you made and then commit those changes:

<code>
$ svn diff index.php
$ svn commit
</code>

Note that svn looks for the EDITOR or SVN_EDITOR environment variables to set the name of the text editor to use when writing commit messages, but you can also specify the commit log message on the command line using:

<code>
$ svn commit --message "Changed the copyright"
</code>

To checkout a working copy of something in the repository, you would use:

<code>
$ svn checkout http://yourserver/svn/www
</code>

or:

<code>
$ svn checkout file:///home/user/subversion/repos/www
</code>

You would use the former snippet if you have subversion setup through Apache to access your repositories, and the latter is if you're just using a local repository.

To view those commit (log) messages for a particular file, use:

<code>
$ svn log index.php
</code>

These are pretty much the basics to using subversion, from a client perspective. In a number of ways, the svn client is very similar to the cvs client; this was done intentionally to make the migration from cvs to svn a lot less painful and make subversion feel a little more familiar to new users.

About

Vincent Danen works on the Red Hat Security Response Team and lives in Canada. He has been writing about and developing on Linux for over 10 years and is a veteran Mac user.

Editor's Picks