Wednesday, September 02, 2009

git-svn and --squash

When you're using git-svn, it's important to remember to use git merge --squash when you're merging a feature branch back to master in preparation for a git svn dcommit. In case you forget (like I just did) here are some simple steps to repair what you've done without dealing with interactive rebase.

The setup (what you should avoid):
git checkout -b feature
hack, hack, hack, merge with changes on master, etc
git checkout master
git merge feature
git svn dcommit

My experience at this point was that the first changeset from the merge was successfully committed to svn followed by the rebase failing. Dcommit actually will commit each revision independently and rebase between them. I was left in interactive rebase. Instead of trying to clean this up iteratively by running through all the changesets I did the following:

(this is still on the master branch)
git rebase --abort
git reset --merge (the merge option sticks everything in your working copy into the index)
git svn rebase (to get the commit that made it to svn)
git merge --squash feature
git commit -m "Here's my feature for all you svn users!"
git svn dcommit

This will successfully push ONE commit with all your remaining changes up to svn. Hope this helps someone who finds themselves in this situation. I also expect to have to read this again next time I forget --squash. Happy coding!

No comments: