How to squash 7 pushed commits into one in to 1 in git?

A srinivas picture A srinivas · May 12, 2018 · Viewed 12.2k times · Source

I have tried multiple ways to squash my remote repo commits but didnt get it right. I want to squash them all and make it one . Below is the list of commits. Below is the summary of my pull request to upstream (which lists 7 commits). I want to list only one instead of 7.

enter image description here

Answer

iBug picture iBug · May 12, 2018
git reset --soft HEAD~7
git add --all
git commit
git push --force

First, reset git index to before the commits you want to squash. Use --soft so that git only resets the index and doesn't touch your working directory. Then create a commit as usual.