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:
- Rebase that branch on the master, so I know that there won’t be any conflicts.
git checkout proper-xml-generation; git rebase master
- Switch back to the master branch.
git checkout master
- Copy the patches.
git format-patch -k --stdout master..proper-xml-generation | git am -3 -k
- 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.