Last Updated: February 25, 2016
· riyadhalnur

Git Squash Commits

To reduce the number of commits in Git when rebasing/merging with another branch or sending in a pull request, you can this Git command to 'squash' the number of commits -

git rebase -i HEAD~[number_of_commits]

For example -

git rebase -i HEAD~2

This will squash/merge/rebase the latest 2 commits in the HEAD branch.

2 Responses
Add your response


Well, I believe that command won't squash by itself. After running that command, you'll be prompted with a editor screen where you can do couple of operations and one of them is squashing commits.

over 1 year ago ·

yes it will open up a interactive session where you can choose the commits to keep which technically is squashing and since we are passing it a number, it will only pull up the specified number of commits in the session

over 1 year ago ·
Filed Under