If last X commits need to be squashed, then the git command will be git rebase -i head~X
. So, for squashing
2 commits:
git rebase -i head~2
- You will be presented with a list of commits in the default editor e.g vim with the oldest commit at the top. In vim, below is how the rebase commits will appear, with the older commit at top and newer commit below it.
- Change flag to
s
orf
depending on whether a squash or fixup is needed. A squash will group all the selected commit messages under the oldest commit. A fixup on the other hand will make the commit messages go away but retain the commit. Below is the how a fixup(flagf
) will look like: - Save and exit. Below is how the
fixed up
commits look like, the fixed up commit message has gone away.
git push --force origin master