Skip to content

Instantly share code, notes, and snippets.

@philbert
Created February 22, 2019 13:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philbert/c13ca7220951970225196cbce9206118 to your computer and use it in GitHub Desktop.
Save philbert/c13ca7220951970225196cbce9206118 to your computer and use it in GitHub Desktop.
The way git commit --fixup --autosquash should work

The way git commit --fixup --autosquash should work

I have an extremely useful alias that I use extensively in my git workflow:

alias gfixup="git commit --fixup HEAD && EDITOR=cat git rebase -i --autosquash HEAD~2 | sed '/^#/ d'"

What it does

Commits changes in the git index and auto-squashes the commit into the previous commit without opening $EDITOR!

The workflow

  1. git add .
  2. gfixup

(note: the rebase will fail if you still have modified files)

The problem it deals with

This is a very common development pattern

  1. Write some code and commit -m "did this thing"
  2. Test and discover a problem and make a new commit -m "fix the thing I just did"

gfixup and clean history FTW!

Don't make sloppy commits like this any longer and always keep the head of your branch in a working state!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment