Last Updated: February 25, 2016
· bjpbakker

Migrate Subversion to Git

The basic migration instructions from Subversion to Git are covered by the (free) Pro Git book.

In short you'll build a file mapping the Subversion username to the user's full name and email. Then you'll fetch all Subversion revisions, tags and branches (using git svn clone), create proper Git tags from the Subversion "tags" (actually: branches), and push everything to a Git remote.

So far I have migrated about 10 subversion repositories to Git. Some of these were 'by the book' and migration went pretty smooth. However, with about half of them the Subversion repository was somehow screwed up, making git-svn not to create folders in refs/remotes/tags but instead keeps special Subversion tag folders in refs/svn/root/tags.

Luckily these folders share the tag name. If you don't care about the commit information of the Subversion tag (i.e. who created the tag, why, and when) you can use these tags directly to create Git tags.

git tag [tag-name] tags/[tag-name]

If you have a whole bunch of tags, it's easy to loop this.

for tag in .git/svn/root/tags/*; do
  name=`basename $tag`
  git tag $name tags/$name

Most tags are release tags so the tag name speaks for itself and whoever created the tag doesn't really matter. And the last commit in the tag is a good-enough approximation of when the tag was created.