3 ms·
I did this for a while but have moved on to git commit --fixup HEAD and you can tack an -e on the end to add more notes in the commit message body. You ca
by sixstringtheory 4y ago
I did this for a while but have moved on to
git commit --fixup HEAD
and you can tack an -e on the end to add more notes in the commit message body. You can fixup prior commits by supplying their short hash, which is how I originally discovered this: I essentially wanted to amend a commit farther back in my branch.
This makes a commit with a “fixup!” prefix that works with
git rebase --interactive --autosquash
you can also form that kind of commit directly, and there is also a “squash!” directive. Now you don’t have to force push amended commits. And it helps sometimes when you accidentally amend something you didn’t mean to–now you can just soft reset to HEAD~1 and try again.
I don’t even bother locally rebasing to autosquash it all anymore since we use squash-to-merge/rebase in github PRs now.
- firesloth 4y agoI did something very similar with a bash function: function git-commit-fixup() { git commit --fixup ":/$*" } alias gcf="git-commit-fixup" # Looks for the most recent commit that matches its arg # eg: we have three commits with messages: # "fix: the thing" # "feat: 5 percent cooler" # "test: test coolness" # then we do some work and git add, then do: gcf cooler # now we have 4 commits: " # "fix: the thing" # "feat: 5 percent cooler" # "test: test coolness" # "fixup! feat: 5 percent cooler" # And autosquash will combine the fixup commit with the appropriate semantic commit as you say. Sadly I haven't been using it much as someone introduced a bunch of commit lint git hooks that choke horribly on the "fixup!" part. And you can't pass --no-verify while rebasing.