There are a number of version control systems available. Originally there was RCS, which was suitable for individuals, but not really suitable for groups of people. It evolved into CVS, which worked pretty well for years, and then Subversion came along, making a better CVS than CVS itself. At the same time, there were a number of other version control systems that were becoming popular that went from a central-repository style to a distributed-repository style. Git is one of these and has proven to be quite popular.
The downside, of course, is that people may be using existing version control systems. Moving from CVS to Subversion is quite straightforward, and moving from Subversion to Git is even more so.
A number of Linux distributions now provide packages for Git, so installing it consists of nothing more than a simple apt-get, yum, or urpmi command. Converting a Subversion repository to Git is just as easy. The only thing that would require some manual work is to manage tags and branches.
Before getting there, you need to have available the git-svn command. This is a tool that allows you to convert Subversion repositories to Git and also allows you to push changes back to the Subversion repository. This could be useful for someone who has to deal with a project's Subversion repository but prefers to use Git.
For most distributions, the package is also called git-svn, so on Fedora you would install it like this:
# yum install git-svn
This will likely bring in a few dependencies. Once the install is complete, determine where your Git repository will live. For instance, you may use ~/svn/ as a top-level directory for Subversion repositories, so using ~/git as a top-level directory for Git repositories would work well. In the ~/git directory create an authors.txt file. This file will map the names of Subversion committers to Git authors, resulting in a correct history of the imported Subversion repository. For projects with a small number of committers, this is quite easy. For larger projects with a lot of committers, this may take some time. The syntax of the file would be:
user = Joe User <email@example.com>
vdanen = Vincent Danen <firstname.lastname@example.org>
The short name is the committer name for Subversion whereas the long form is the user's full name and e-mail address, as used by Git.
The final step is to clone the Subversion repository, which creates a local Git repository based on it. Assuming your repository uses the standards of /trunk, /tags, and /branches, use:
# git svn clone —no-metadata -A authors.txt -t tags -b branches -T trunk https://svn.example.com/svn/repo
This will use the svn repository https://svn.example.com/svn/repo as the repository to clone. The -t option specifies the location of any tags, -b for branches, and -T for the main trunk. Modify the command to suit; if you get it wrong, simply remove the local Git repository, adjust the command-line options, and try again. The Git clone does not change the original Subversion repository at all, so is safe to run as many times as required.
The clone command will produce output like this:
Initialized empty Git repository in /home/user/git/repo/.git/
r1 = 94f30e5958d5267e8f2fb3547bc159eac4309b16 (trunk)
r372 = 8a8d1185d441ef1d8b97e913384a54c1344b636f (trunk)
Checked out HEAD:
The size of the Subversion repository to clone will determine how long the cloning takes.
You now have a working Git repository clone of the original Subversion repository. If this is a personal repository with no branches or tags, then you are done. If this is a project repository that needs to be shared, then you need to push to or create a public repository. If you have branches and tags that you want to convert, you will need to make use of the "git branch" and "git tag" commands. The man pages for Git are quite comprehensive and are definitely worth looking into.
If you feel the need, converting from Subversion to Git is very easy and straightforward. The learning curve may be more difficult and time consuming, so even if you are interested in learning how to use Git, cloning an existing Subversion repository is a great way to learn about it with "real" data. And if you mess something up, you can always re-import the original Subversion repository and try again.
Get the PDF version of this tip here.
Delivered each Tuesday, TechRepublic's free Linux and Open Source newsletter provides tips, articles, and other resources to help you hone your Linux skills. Automatically sign up today!
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.