Commit Early, Commit Often – git merge –squash

Canva - Acorn Squash, Autumn, Vegetable, Food, Harvest.jpg


In a previous post I described one of the ways that history can be re-written in git with an interactive rebase by “squashing” multiple commits together.  Since we are heading into Fall, I will demonstrate a similar feature, merge --squash.

The Merge Squash

In the example below, feature branches off of master at “Commit One”.   feature has two additional commits, “Feature Commit One” and “Feature Commit Two”.  Here is the output of git log --all --graph --decorate --oneline:

* 006ffbd (HEAD, feature) Feature Commit Two
* aca7e1d Feature Commit One
| * 8292a51 (master) Commit Two
* d7288cc Commit One

While on master, executing git merge feature --squash will merge feature into master. By default the merge will pause prior to committing the changes.

Squash commit -- not updating HEAD
Automatic merge went well; stopped before committing as requested

If there were no merge conflicts, then the changes will be ready to commit at this point. git commit -m 'Merged in my feature'

* 1727f02 (HEAD, master) Merged in my feature
* 8292a51 Commit Two
| * 006ffbd (feature) Feature Commit Two
| * aca7e1d Feature Commit One
* d7288cc Commit One


In this short tutorial I demonstrated another useful tool that can be used when you don’t care about retaining the history of a particular feature that is spread across multiple commits.  Here is more reading.

Leave a Reply


You are commenting using your account. Log Out /  Change )

Google photo


Twitter picture


Facebook photo


Connecting to %s