Thursday, August 05, 2010

Some clarifications on living with Git and SVN

This post is part of a series on Git and Subversion. To see all the related posts, screencasts and other resources, please click here

I'm afraid I exaggerated in my previous posts, and given the impression that living with Git and Subversion in parallel is easy. I would update it, but Blogger is refusing to edit the post without screwing it up. So here it is in clear text:

Be prepared to face some major constraints in using Git against a Subversion repo, compared to how it using Git standalone.

The manual says it best:
The git svn tools are useful if you’re stuck with a Subversion server for now or are otherwise in a development environment that necessitates running a Subversion server. You should consider it crippled Git, however, or you’ll hit issues in translation that may confuse you and your collaborators. To stay out of trouble, try to follow these guidelines:
  • Keep a linear Git history that doesn’t contain merge commits made by git merge. Rebase any work you do outside of your mainline branch back onto it; don’t merge it in.
  • Don’t set up and collaborate on a separate Git server. Possibly have one to speed up clones for new developers, but don’t push anything to it that doesn’t have a git-svn-id entry. You may even want to add a pre-receive hook that checks each commit message for a git-svn-id and rejects pushes that contain commits without it.

As you can understand, this takes some of the fun out of using Git (although it's still a much better SVN client than SVN). Another clarification:

In the previous post, I stated that you have to manually enter a value into .git/refs/remotes/git-svn. It appears that you have to have to repeat this every time new changes come into the SVN-fetching repository. Fortunately, there's an easier way to update the ref:

git update-ref refs/remotes/git-svn refs/remotes/origin/master

You have to do the above after pulling from the SVN fetching repo, and before you run git svn dcommit (found this here).  This seems a bit awkward, and you'd wonder why this isn't built into git-svn. I asked about it on the #git IRC channel, and they said that the "recipe" configuration doesn't support a single url tracking branch. It has to be a standard -s layout. I should test this though, currently I'm just syncing with one branch in SVN. In the mean time, I dcommit with a little script that runs update-ref first, and then does the dcommit.

Some more resources: