Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitflow: Should I squash commits when merging from a release branch into master?

I am going to merge my release branch to master and I am wondering if I should squash the commits from develop into a single merge commit when merging into master.

General documentations about git flow contain figures like this one from in the Atlassian page:

enter image description here

In those figures only single commits appear on master instead of all commits made to develop.

Acctually, I like the idea of having a master branch which release commits only.

Should I retain all commits on develop when merging into master? Or do you squash the commits before merging to master when following Gitflow?

Link to the source article: Gitflow Workflow - Atlassian

like image 649
Rika Avatar asked Dec 14 '16 10:12

Rika


People also ask

Should you squash merge commits?

Before you start, keep in mind that you should squash your commits BEFORE you ever push your changes to a remote repository. If you rewrite your history once others have made changes to it, you're asking for trouble… or conflicts.

How do you squash commits when merging?

To enable commit squashing as the default option in your repository: Navigate to your chosen repository and open the Settings sub-tab. Open the General Settings page. Check the box for Squash commits on merge default enabled.

What happens if you squash a merge commit?

Specifically, squashing throws away all our hard work in building a specific commit graph. Instead, squashing takes all the changes and squashes them together into a single commit. It's as if you made all the changes at one sitting and committed them as a unit.


1 Answers

In my opinion, and bear in mind, this is just an opinion, and you will likely get different answers, you should NOT squash the commits when merging into master from the develop branch. Doing so would lose a lot of the history of the changes that have been made. For example, almost all the commits I make are tagged with an issue number, so that there is full trace-ability back through the git history into the issues that were raised, and why changes were made.

More to the point, you shouldn't be merging directly from develop into master. Assuming you are following git-flow, then this transition should be being done through a release branch.

If you had asked whether, when on a feature or hotfix branch, should the commits be squashed then that would have been a different answer. In these cases, arguably the branch should be small enough to warrant only a single commit, so in these situations, I almost always rebase and squash commits into a single one, prior to merging into the target branch.

like image 109
Gary Ewan Park Avatar answered Sep 19 '22 04:09

Gary Ewan Park