git branches with subversion

I like using git, particularly in combination with git svn. It makes it really easy to work with version control offline. But there’s a problem: branches.

Now git is really good at using branches. Unfortunately, git svn can’t cope very well with pushing one of git’s merges back into subversion. It gets really confused. Trust me.

Thankfully, I’ve found an easy way to do it: patches.

In the git format-patch man page, there’s a useful example:

  % git format-patch -k --stdout R1..R2 | git-am -3 -k

That is, make a mailbox full of all the changes between R1 and R2, then apply them to the current checked out branch. Essentially, “copy the changes on that branch to this one”.

I just needed to do this with a project I’ve been playing with. I’d been working on a branch proper-xml-generation. In order to merge it, I had to:

  1. Rebase that branch on the master, so I know that there won’t be any conflicts.
    • git checkout proper-xml-generation; git rebase master
  2. Switch back to the master branch.
    • git checkout master
  3. Copy the patches.
    • git format-patch -k --stdout master..proper-xml-generation | git am -3 -k
  4. Pump the results back into subversion.
    • git svn dcommit

And hey presto, the branch is back in subversion. It looks a bit weird having 14 commits in a few seconds though.

The main disadvantage of this is that it’s pretty much a one-time push back into subversion. You don’t get all the nice usual features of git, where you can make more changes on the branch and merge them. But it’s been sufficient for me for a little while now, so I thought I’d share it.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s