Thursday, September 9, 2010

Fixing whitespace issues with git rebase

We're using a rebase and merge style approach for getting topic branches into our master branch.

Typical usage looks like this:
# Get the topic branch
git checkout topicbranch
# Sit it ontop of master
git rebase master
# Clean up all the commits so its nice and tidy
git rebase -i master
git checkout master
git merge topicbranch
Now if you add a --whitespace=fix to the first rebase stage, git will clean up all the odd whitespace at end of line stuff that git complains about and that editors can leave in there accidentally.

However this only works if your branch is not already branched off master. If your branch already contains the master head you'll just get the message:
Current branch topicbranch is up to date.

It turns out its easy to make the rebase happen:
git rebase -f master --whitespace=fix

No comments:

Post a Comment