squash commits into one code example

Example 1: squash commit history git

# THIS TURNS YOUR WHOLE COMMIT HISTORY INTO ONE SINGLE COMMIT!
# BE CAREFUL!

git rebase --root -i

# In your editor, for each commit except the top, change `pick` to `squash`

Example 2: squash pushed commits

git rebase -i origin/master~4 master
git push origin +master

Example 3: squash commits on branch

git rebase -i HEAD~20

Example 4: squash 3 commit

$ git rebase -i HEAD~3

Example 5: squash commits in git

git reset --soft HEAD~3 &&
git commit