Suppose you have:
A-B-C
Now your build/test fails. The fix should be merged in A. My current work-flow is like this:
$ git
I created some aliases to make it easier to use the git commit --fixup
and git commit --squash
commands added in git 1.7. Add these to your ~/.gitconfig
:
[alias]
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autosquash $REV^' -
squash = !sh -c 'REV=$(git rev-parse $1) && git commit --squash $@ && git rebase -i --autosquash $REV^' -
Usage:
$ git commit -am 'bad commit'
$ git commit -am 'good commit'
$ git add . # Stage changes to correct the bad commit
$ git fixup HEAD^ # HEAD^ can be replaced by the SHA of the bad commit
The bad commit can be several commits back.