There are quite a few working answers here, but I found this the easiest. This command will open up an editor, where you can just replace pick
with squash
in order to remove/merge them into one
git rebase -i HEAD~4
where, 4
is the number of commits you want to squash into one. This is explained here as well.
If you are looking to squash
the commits which also includes the very first commit, then use this command
git rebase -i --root