Skip to content

Instantly share code, notes, and snippets.

@bkeepers
Created February 19, 2013 14:12
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bkeepers/4986257 to your computer and use it in GitHub Desktop.
Save bkeepers/4986257 to your computer and use it in GitHub Desktop.
Git aliases to make new commits that fixup or are squashed into previous commits
[alias]
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && git rebase -i --autosquash $REV^' -
squash = !sh -c 'REV=$(git rev-parse $1) && git commit --squash $@ && git rebase -i --autosquash $REV^' -
$ git commit -am 'bad commit'
$ git commit -am 'good commit'
# Stage changes to correct the bad commit
$ git add .
# Fixup the bad commit. HEAD^ can be replaced by the SHA of the bad commit
$ git fixup HEAD^
@elmarx
Copy link

elmarx commented Feb 28, 2017

You can even skip a step for fixup if you set the git-editor to true:
fixup = !sh -c 'REV=$(git rev-parse $1) && git commit --fixup $@ && GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash $REV^' -

@KUGA2
Copy link

KUGA2 commented Feb 21, 2022

Another useful addition is --autostash (to rebase), so the command will not be interrupted when you got unstaged changes

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