Git rebase can easily accomplish this without the need for git merge --squash. In this example, we will squash the last three commits.
If you want to start with a new commit message from scratch, this is sufficient:
shellgit reset --soft HEAD~3 git commit
If you want to edit a new commit message combined with the existing commit messages (i.e., similar to the pick/squash/squash/…/squash sequence in the git rebase -i interactive command), you need to extract these messages and commit them with git commit:
shellgit reset --soft HEAD~3 && git commit --edit -m"$(git log --format=%B --reverse HEAD..HEAD@{1})"
Both methods squash the last three commits into a single new commit in the same way. A soft reset simply moves HEAD to the last commit you do not want to squash. A soft reset does not touch the index or working tree, leaving the index in the state required for the new commit (i.e., it already contains all the changes from the commits you are discarding).