Squash Merge
Squash merge is another approach when you merge branches. This approach is useful when you don't want to keep every single detail of change histories in the master branch.
When you run the git merge
command with the --squash
option, all the changes made in the target branch are reflected in the destination branch. However, the command doesn't create a new commit. The changes are only reflected in the Working Tree and INDEX (see the main figure).
When you want to proceed with the change, you need to make a new commit by running the git commit
command. This command records only one new commit under the master branch. All commits under Branch_A are combined (squashed) in the new commit.
We'll explain squash merge with the --squash
option in more detail with command line examples below.
Command Line Example
The command line image below is a demonstration of the commit and merge actions, which are the same as the upper illustration in the main figure. M1, M2, M3, A1, and A2 are the commit messages that were already made before. We'll explain the commands and responses in the command line in six steps.
- Confirm the pre-merge commit history status by running the
git log
command on the master branch. You can see that the commit histories and branch statuses are the same as the ones illustrated in the main figure. (In this status, the merge operation done on the previous page has been reversed, and commit M4
Subscribe now for
uninterrupted access.