Skip to content

Instantly share code, notes, and snippets.

@csebille
Forked from jbub/squash-commits.sh
Created November 8, 2018 12:10
Show Gist options
  • Select an option

  • Save csebille/19da6fabfc3a62810371d1bf907daa2b to your computer and use it in GitHub Desktop.

Select an option

Save csebille/19da6fabfc3a62810371d1bf907daa2b to your computer and use it in GitHub Desktop.
git squash last two commits into one
git rebase --interactive HEAD~2
# we are going to squash c into b
pick b76d157 b
pick a931ac7 c
# squash c into b
pick b76d157 b
s a931ac7 c
# after that just edit the commit message
# This is a combination of 2 commits.
# The first commit's message is:
b
# This is the 2nd commit message:
c
@csebille
Copy link
Author

csebille commented Nov 8, 2018

from comment in forked gist 👍

Great gist. FYI for convenience you can make the parameter of the fixup git alias optional and set it to a default value of 1 by replacing ${1} with ${1-1}, e.g.:
fixup = "!f(){ git reset --soft HEAD~${1-1} && git commit --amend -C HEAD; };f"

So then you can just do:
git fixup # merges the last commit into its parent

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