xxxxxxxxxx
git reset --soft HEAD~3 &&
git commit
xxxxxxxxxx
git reset --soft HEAD~2
git commit -m "new commit message"
git push -f
xxxxxxxxxx
There are two options to squash the last N commits into a single commit include both of the below-mentioned options in your answer
If you want to write the new commit message from scratch use the following command
git reset –soft HEAD~N &&git commit
If you want to start editing the new commit message with a concatenation of the existing commit messages then you need to extract those messages and pass them to Git commit for that I will use
git reset –soft HEAD~N &&git commit –edit -m”$(git log –format=%B –reverse .HEAD@{N})”
xxxxxxxxxx
# Reset the current branch to the commit just before the last 12:
git reset --hard HEAD~12
# HEAD@{1} is where the branch was just before the previous command.
# This command sets the state of the index to be as it would just
# after a merge from that commit:
git merge --squash HEAD@{1}
# Commit those squashed changes. The commit message will be helpfully
# prepopulated with the commit messages of all the squashed commits:
git commit