Friday, March 7, 2008

Converting a Subversion repository to Git

Previously, I had tried converting from a local Subversion repository to Mercurial. I thought I would try converting the same projects into Git.

Firstly, to install Git on the mac with Subversion support:
$sudo port install git-core +svn

Secondly, setup an authors file to map Subversion committer names to appropriate Git format.

Now my local svn repository has multiple projects in it. The layout is like:


bar/artifacts
branches
tags
trunk
foo/artifacts
branches
tags
trunk

git-svnimport seems to expect the standard svn directories (branches, tags, trunk) to be at the root. So for each import, the paths to these directories need to be specified explicitly.

Foo is a fairly new project with no branches, 2 tags and about 27 commits.
$git-svnimport -C foo -A authors.txt -T foo/trunk -t foo/tags file:///path/to/repos

Completed with no errors.

Bar is an older project with 1 branch, 13 tags and about 464 commits.
$git-svnimport -C bar -A authors.txt -T bar/trunk -t bar/tags -b bar/branches file:///path/to/repos
Initialized empty Git repository in /Users/cbrad/tmp/bar/.git/
...
fatal: Needed a single revision
64: cannot find commit 'origin'!
...
Use of uninitialized value in system at /opt/local/bin/git-svnimport line 877.
fatal: Failed to resolve '' as a valid ref.
Cannot create tag 10:

There were many of the 'fatal: Needed a single revision' errors.

This article mentions the potential for issues if the svn repository layout had changed over time. The bar project was one of the first things in this repository, so it has been moved and changed several times, as the overall repository layout evolved. I tried doing imports around the movement points in the history, with the view to merge (like in this post), but that also failed.

I guess I can start a fresh Git repository, add the current project head and keep the svn repository lying around for reference, but I was hoping not to have to do that.

No comments: