I've found that git rebase -i $some_commit and adding break lines is very handy for fixing up things in an earlier commits. I then sometimes use x ./check after each subsequent commit to quickly identify any breakage in the commit where it happens.
After each fixup due to break or x, I need to run:
git commit --amend -a
git rebase --continueIf the rebase stops because there is a merge conflict that I need to fix, the proper thing to do is:
git add <file_with_conflicts>
git rebase --continueIf I accidentally use git commit --amend -a it will cause the commit that needs to be fixed to be squashed into the previous commit. I've been bitten many times.
To protect against this, I've added the following to .git/hooks/pre-commit:
#! /bin/bash
exec 1>&2
top=$(git rev-parse --show-toplevel)
if [[ -f $top/.git/rebase-merge/stopped-sha ]]; then
cmd=$(ps -o command= -p $PPID)
if [[ $cmd == *--amend* ]]; then
echo "$0: refusing to amend while fixing up a rebase commit"
echo ""
echo "Use: git rebase --continue"
exit 1
fi
fiNow I'm protected:
$ git commit --amend -a
.git/hooks/pre-commit: refusing to amend while fixing up a rebase commit
Use: git rebase --continue