Squashing is available for commits that meet the following requirements:
- Selection contains more than one commit
- Genealogically consecutive
- Chronologically consecutive
- The oldest commit in the list has a parent
If all these conditions are met, the Squash option appears when you right click the commit node.
Clicking the squashed commit will display the commit message in the right panel. You can click on the commit message to amend it and consolidate all of the commit messages from your squashed commits.
Pushing a squashed commit
In general, you should not push commits to your remote that you intend to squash, but what happens if you have already pushed them and you squash locally? Your local branch has the squashed commit, but your remote branch still has all of the commits.
When you push to your remote, you will receive a warning that your current branch is behind the remote branch. This is expected, because the HEAD of your current branch is no longer a descendent of the remote branch’s HEAD.
In this instance, a will allow you to push the squashed commit to your remote and retain the clean history of your local branch.
You will see a warning letting you know that is a destructive action, but this is expected because we have rewritten our branch’s history by squashing commits.