A while ago on the thoughtbot blog there was a great post about auto-squashing git commits. This approach is ideal for fixing bugs or mistakes in commits I’ve made some commits ago.
One problem arose though: I am lazy.
To make a fixup commit you need the commit SHA or another type of reference. I don’t know the SHAs by heart or how many commits ago it was so I need to copy paste the SHA from
git log to the terminal. That’s mouse movement I’d like to avoid.
To help me I wrote a small executable for the ZSH shell to give me a list of commits I can select for a fixup.
$ git-fixup 1 Configure ctags 2 Ignore rspec examples.txt 3 Update snippets 4 Remove accidentally committed comment 5 Allow shrinking and growing of windows 6 Update README 7 Add status alert 8 Add bluetooth toggle trigger 9 Supertab, use C-N as default 10 Add system sleep trigger Commit to fixup?: 3 [master 6fe0593] fixup! Update snippets 1 file changed, 4 insertions(+), 4 deletions(-)
git fixup both work.
Where to find it
I’ve added this executable to my dotfiles here. You are free to add it to your ZSH config, rename it, change it, etc.
I hope you’ll find it useful.
The executable lists the last 10 commits by default. You can have it list more by giving it an argument:
git-fixup 20 lists the last 20 commits.
When the prompt
Commit to fixup? appears you enter the number in front of the subject of the commit you want to fixup then press
If you enter nothing when prompted it will exit without making a fixup commit.