Last Updated: February 25, 2016
· riyadhalnur
10309058 10152457564452360 4465802230248535815 n

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.

Say Thanks

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 ·
10309058 10152457564452360 4465802230248535815 n

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