Squash and Merge
Introduction
Squashing lets you tidy up the commit history of a branch when accepting a merge request. It applies all of the changes in the merge request as a single commit, and then merges that commit using the merge method set for the project. The squashed commit’s default commit message is taken from the merge request title.
When to Squash?
For instance, you may have worked on a project and generated plenty of commits for your reference. At some point, you will surely want to commit and consequently merge your work to the master branch. This is one instance when you need to squash all the commits into one so that all the previous as well the current commits are merged into one.
What happens when you squash commits?
Squashing a commit means, from an idiomatic point of view, to move the changes introduced in said commit into its parent so that you end up with one commit instead of two (or more). If you repeat this process multiple times, you can reduce all commits to a single one.
Let’s assume you have the following commit log in the branch you want to merge as part of your merge request:
Here we want to squash the fifth, sixth, and seventh commit and create a new commit on top of commit 64710 (lets name it as target).
After Squash:
This results in a single commit with a commit message that is a concatenation of all three messages. All intermediary commits are gone and ready to merge!
How to perform Squash and Merge for your merge request in the ARM tool
All you have to do is select the Squash and Merge checkbox while creating a merge request.
Explore: Version Control > Merge Request History > New Merge Request.
When to delete source branch in squash merge?
Squash merging condenses the history of changes in your default branch, so it is important to work with your team to decide when you should squash merge and when you want to keep the full commit history of a topic branch. When squash merging, it’s a good practice to delete the source branch.
Last updated