I think it's easier to use git reset
with the soft
option.
git reset --soft HEAD~7
If you are not sure about the HEAD~7
, do git log --oneline
, copy de hash of the 8th commit, and:
git reset --soft <hash_your_commit>
Now, all your files you have modified during the last 7 commits are in the staging area and ready for commit:
git commit -m "7 commits squashed into 1"
Finally, to that commit to the remote
, you'll have to use the -f
or --force
option if one or more of the 7 commits were already on the remote
. That way, those commits will disappear from the remote
as well.
// if none of the 7 commits are on the remote
git push origin branch
//else
git push -f origin branch