Skip to content

Instantly share code, notes, and snippets.

@istumpf
Forked from jbub/squash-commits.sh
Last active February 22, 2021 18:18
Show Gist options
  • Select an option

  • Save istumpf/ddf477771f7647f83c5fd3afc5c44954 to your computer and use it in GitHub Desktop.

Select an option

Save istumpf/ddf477771f7647f83c5fd3afc5c44954 to your computer and use it in GitHub Desktop.
git squash last two commits into one

call git rebase with the number of commits to be squashed

git rebase --interactive HEAD~2

the list of commits will be displayed

pick b76d157 b
pick a931ac7 c

mark the commits to be squashed in this case squash c into b

  • press insert to enter edit mode
  • mark commits to squash replacing pick by s or squash
  • leave the first commit as pick
  • to save and exit press ESC then type :wq (write quit)
pick b76d157 b
s a931ac7 c

edit the commit message

  • press insert to enter edit mode
  • edit the commit message
  • to save and exit press ESC then type :wq (write quit)
# 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment