Read more

Git shortcut to fixup a recent commit

Deleted user #4117
September 29, 2021Software engineer

git --fixup is very handy to amend a change to a previous commit. You can then autosquash your commits with git rebase -i --autosquash and git will do the magic for you and bring them in the right order. However, as git --fixup wants a ref to another commit, it is quite annoying to use since you always have to look up the sha of the commit you want to amend first.

Illustration money motivation

Opscomplete powered by makandra brand

Save money by migrating from AWS to our fully managed hosting in Germany.

  • Trusted by over 100 customers
  • Ready to use with Ruby, Node.js, PHP
  • Proactive management by operations experts
Read more Show archive.org snapshot

Inspired by the shortcut to checkout recent branches with fzf, I built an alias for selecting the commit I want to fixup:

alias fixup='git log --oneline | fzf | awk '\''{print $1}'\'' | xargs -I '\''{}'\'' git commit --fixup {}'

After you have used fixup you still will have run

git rebase -i --autosquash HEAD~n

Demo:

Image

Side note:

To further save a few keystrokes, you can tell git to always autosquash.

git config --global rebase.autosquash true
Posted to makandra dev (2021-09-29 18:15)