Tuesday, June 9, 2009

Use Git to do your svn merges

I've been using git-svn as a frontend to svn. Git provides so much power that it makes it enjoyable to use source control. Despite the comment in the man pages of git-svn that says that it considered bad form to use git to do your svn merges, I have found it much more useful. The way I do my merges is that I just do

git checkout branchtomergeinto
git merge --squash branchtomergefrom

The --squash tells git to mash all the commits into one patch and not to commit, so that you can check it out first. This inevitably leads to some conflicts, so I then use

git mergetool

to go through and resolve all my conflicts using "meld". After you're all done fixing the conflicts and recompiling to make sure everything is good.

git commit

And type a message that will be appropriate in an svn context so maybe

git commit -m "Merging from funkycool branch r1500"

Then do your git svn dcommit. After doing a few merges out from trunk into a longer term project I was noticing that I was having to remerge alot of things I had formerly merged. This is because when you do a git svn dcommit git forgets about the tracking of the merges that you have done. I started hunting for a solution and found this article about using git grafts to restore svn merge history. Git grafts are awesome in that they let you declare what has been merged manually. By adding the git grafts for the merges you have done, the next time you merge out you will have far fewer conflicts. Git does it again.

1 comment:

Anonymous said...

The information here is great. I will invite my friends here.

Thanks