squashing a specific number of commits
choose how many commits back you wanna squash into 1
$ git rebase -i HEAD~8
the current commit log
pick 1d402c35 some msg
pick 8151d8d8 some msg
pick e48f8da5 some msg
pick 3734d917 some msg
pick 760702c5 some msg
pick 7936da9a some msg
pick d54b8767 some msg
pick 5e5da155 some msg
pick which one you wanna squash the others into
pick 1d402c35 some msg
squash 8151d8d8 some msg
squash e48f8da5 some msg
squash 3734d917 some msg
squash 760702c5 some msg
squash 7936da9a some msg
squash d54b8767 some msg
squash 5e5da155 some msg
the current commit messages
# This is a combination of 8 commits.
# This is the 1st commit message:
some msg
# This is the commit message #2:
some msg
# This is the commit message #3:
some msg
# This is the commit message #4:
some msg
# This is the commit message #5:
some msg
# This is the commit message #6:
some msg
# This is the commit message #7:
some msg
# This is the commit message #8:
some msg
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
update your commit message
# This is a combination of 8 commits.
# This is the 1st commit message:
some msg
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
force push dat shiz
$ git push origin branch-name --force
squashing commits which contain merges from other branches
$ git rebase -i master
the current commit log
pick 7936da9a some msg
pick d54b8767 merge from xxx
pick 5e5da155 some msg
pick which one you wanna squash the others into
pick 7936da9a some msg
squash d54b8767 merge from xxx
squash 5e5da155 some msg
update your commit message like normal the force push it
$ git push origin branch-name --force