4 ms·
One of the nice workflows that's already built in to the git command line tools is this one. When you're working on a branch and realise that a commit you made
by mhw 10y ago
One of the nice workflows that's already built in to the git command line tools is this one. When you're working on a branch and realise that a commit you made a few commits back has a mistake in it:
# 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.
- bennofs 10y agoEven better in combination with the `:/grep` syntax that allows you to specify the commit by grepping the commit messages, prefering more recent commits: `git commit --all --fixup ':/implement some feat'`.
- mhw 10y agoMmm - nice. Glad I posted it now, as I didn't know that variation!
- dahart 10y agoYeah, super useful, I can second setting auto squash in the config. I was almost thinking of saying the same thing, but I realized this post is probably deliberately avoiding rebase. This workflow is advanced relative to the problems described, and you'd agree those command lines are going to look pretty intimidating to a novice, right? They were to me the first time, there's a lot to understand before they're comfortable.
- mhw 10y ago> This workflow is advanced relative to the problems described 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.
- aromatt 10y agoYep. I find that most of the time, the commit I want to fixup is my last one, so I don't even need the interaction. I use this script almost every day: 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