Wednesday, September 19, 2007

Using git to cope with crazed svn repositories

If you ever find yourself working with a gnarly svn repo you may want to give git-svn a try. You will be able to do your collaboration with git and then dump your changes back to svn. The truth is many large projects are not yet ready to ditch svn completely and there may exist tooling already for svn that your team needs (and doesn't have time to rewrite). For this reason exists git-svn.

Initialize your svn aware git repository:
mkdir mywork; cd mywork
git svn init http://workserver.com/path/to/the/code/you/care/about
git svn fetch -r [revision you care about]

The reason I'm encouraging you to only grab the code you care about is because if you are working with a truly crazed svn repository things can get unnecessarily complex. When I did a full svn import of the root on the svn repo where I work it took over 3 days to finish on a good connection. The truth is there was only one branch that I really cared about.

If you are working on a more complex project and having to deal with other groups that are using svn you may have to do a slightly more sophisticated initialization:

git svn init https://workserver.com -T path/to/the/repo/you/want/to/commit/to -b dir/that/has/branches/of/other/teams

The main thing to understand is that git-svn provides two-way communication between git and only one branch in svn. The path you specify for '-T' needs to be that one branch. It doesn't actually need to be the real trunk from svn's point on view--it's just the particular path you care about.

Once you have initialized your repo you will need to do some fetching. Again, you don't want to fetch more than you need. One thing that was not intuitive for me was how the fetch works. I immediately tried to check the latest revision and nothing was getting pulled down. The trick is to pull down revision that actually have commits. Use 'svn info' to find out the last revision where a particular path was changed. You will need to do this for your 'trunk' and any other branch you care about.

No comments:

Tags

my google reader feed