How to Perform a git Squash Merge to Turn a Lengthy git Commit History into One Merge Commit and Eliminate Intermediate Steps

Chris Simpkins
sweetmeat
Published in
2 min readOct 7, 2017
photo by Clark Young https://unsplash.com/photos/fQxMGkYXqFU

This article demonstrates how to use git merge --squash to eliminate intermediate git commit history steps between branches so that you can merge a branch as a single commit that includes all file changes.

Problem

The git history can become cluttered with intermediate file changes in a pattern like A > B > C > D. This solution is for situations when you want the git history to reflect only the transition from the beginning state A to the end state D in a single commit for all files following a branch merge.

git Documentation

The formal definition of the git merge --squash approach from the git documentation is:

Produce the working tree and index state as if a real merge happened (except for the merge information), but do not actually make a commit, move the HEAD, or record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit).  This allows you to create a single commit on top of the current branch whose effect is the same as merging another branch (or more in case of an octopus).

Usage

$ git checkout [branch to receive merge]
$ git merge --squash [branch to merge]
$ git commit -m "[commit message]"

Example

$ git checkout master
$ git merge --squash dev-build-mods
$ git commit -m "modify build approach with new buildsomething dependency"

--

--