How to prevent Gitlab from creating extra merge commit on branch merge
Solution 1
TL;DRYour Project > Settings > General > Merge Request Settings > Fast-Forward Merge.
Personally, I also prefer to do squash commits
on every merge.
I think GitLab supports this now.
Steps
- Go to your
project
- Navigate to project
settings
(Note: This is NOT the profile settings available on the top right) - Go to
General
tab. - Navigate to
Merge Request Settings
section - Choose
Fast-Forward Merge
.
Solution 2
I should have created a squash of commits on branch
With GitLab 13.3 (August 2020), there is a new option which is interesting in your case:
Squash Commits Options
Squashing commits in Git is a great way to combine several commits into a single one.
It’s great for grouping several commits, which by themselves may provide little historical value, into a single large commit before pushing upstream.
Pushing a single commit allows for a more meaningful commit message, as well as ensuring the group of commits provides a “green” continuous integration pipeline.In GitLab 13.3 we are adding configurable defaults for squashing commits, allowing project maintainers to configure the option to suit their preferred workflow.
Because changing squash configuration may introduce unwanted behavior, configuration has not been changed for new or existing projects. With 314 upvotes 👍, this is one of the most highly requested improvements by the community and we hope it allows more users to use this powerful feature.
See Documentation and Issue.
Related videos on Youtube
TechCrunch
Updated on June 04, 2022Comments
-
TechCrunch almost 2 years
I use GitLab in my project. I'm exploring Merge Requests feature.
- I created a
topic_branch
frommaster
. - Made a bunch of commits on
topic_branch
. - Pushed
topic_branch
to remote. - Created a merge request on
master
to pull changes fromtopic_branch
. - On accept merge in Gitlab,
master
pulled all the commits and also created a merge commit which is horrible to see duplication of code.
I should have created a squash of commits on branch and then created merge request. But still
master
would have two new commits, one from the branch and another one would be merge commit. I'm assuming, if I do this from command line i.e,- checkout
master
- merge
topic_branch
intomaster
- commit / push
master
In this case, there would be only 1 commit onmaster
.
How to achieve this from GitLab ?
- I created a
-
k3liutZu about 8 yearsThis doesn't answer the question. Manually yes, you can do all flows you need. But from GitLab's interface there doesn't appear to be a good solution to not have an extra Merge commit.
-
Mykola Gurov about 8 years@k3liutZu it is up to user whether he wants or not to have a merge commit irrespectively of what gitlab thinks of that. The author of the question would obviously prefer not to have one (me to).
-
Nakilon almost 8 years@CSchulz, we have some free Gitlab instance and Merge requests create merge commits even while rebasing. Maybe you mean EE has some "revert" button? You can revert merge commits from console and without need of --force.
-
CSchulz almost 8 yearsSorry I missed the detail about the rebase. I will delete this comment soon.
-
CSchulz almost 8 yearsNote: The rebase before merge is an Enterprise Edition feature.
-
Fancyoung over 3 yearsPS: the
Fast-Forward
setting only supported in EE or CE(10.1+)