by mhw · 10y ago · 0 comments
# Make correcting change
git commit --all --fixup=<ref of commit with mistake>
# Continue working on branch, then at some point
git rebase --interactive --autosquash
The --fixup option creates commits with subjects formatted like 'fixup! previous commit subject'. --autosquash uses these subjects when building the interactive rebase list.Handy enough that I set rebase.autoSquash to true in my ~/.gitconfig so 'git rebase -i' always works like this.
Yeah, true. I posted it mostly because one of the bigger threads of comments was advocating using a GUI instead of the CLI. I'm not going to argue that the git CLI is simple, but it does have some nice features to support specific common workflows.
last_commit=$(git log --oneline | head -1 | cut -d' ' -f1)
git commit -a --fixup ${last_commit}
GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash ${last_commit}~1