Migrating an SVN Repository to Git


Often, when considering a new version control system, the easiest way to get started is to migrate an existing repository over to it. With Git, it is fairly straightforward to migrate an existing Subversion repository, including all history, over to Git.

Gathering User Information

Git, unlike Subversion, stores the both the name and email of the committer, so you will want to create a text file with a user map which will be used make sure each commit retains the correct committer info. To generate this file, run:

$ svn log -q REPOPATH | grep -e '^r' | awk -F'|' '\{print $2}' | sort -u | sed 's/^ *\\(.*\\) $/\\1 = \\1 <USER@DOMAIN.COM>/g' > authors.txt

This will create authors.txt with all the committers from the SVN repository specified by REPOPATH with dummy Git committer information, such as:

$ svn_committer = svn_committer <USER@DOMAIN.COM>

Once this is done, you can edit the file, and enter in each users actual name and email address on the right side of the equals sign. This will be the Git author information used during the migration.

Cloning the SVN Repository

Once your user mapping is completed, you can now clone the SVN repository directly using git svn clone.

NOTE: Unfuddle SVN repositories are created by default without the standard repository structure of trunk, branches, and tags in the root directory, however if you follow this format, you will also want to include --stdlayout in the command. If you follow a different directory structure, you can specify this with other options. Please see the git-svn Manual Page for more information.

$ git svn clone [subversion_repository_url] --no-metadata -A authors.txt ./repo

Cleaning Up

If you had tags in the SVN repository, these are now remote branches for each tag. To display these you will want to run:

$ cd /path/to/repo
$ git branch -r

For each tag displayed you will want to run:

$ git tag tagname tags/tagname
$ git branch -r -d tags/tagname

Pushing to Unfuddle

Congratulations! You have created a Git repository with all the history, and authors set correctly. Now, we are on to the last step. You will want to push the Repository up to Unfuddle so it is available to other users in the account. If you haven't already created an empty Git repository in your account, do that now. Then follow these commands:

$ cd /path/to/repo
$ git remote add unfuddle https://subdomain.unfuddle.com/git/subdomain_abbreviation/
$ git config remote.unfuddle.push refs/heads/master:refs/heads/master
$ git push unfuddle master

NOTE: If the amount of data you push exceeds Git’s http post buffer size, which is default to 1MB, an error occurs. To prevent this, run this command that will increase it to 500MB:

$ git config --global http.postBuffer 524288000

Now this repository can be accessed by users in the project simply by cloning the repository using git clone. Enjoy using Git!