I use GitLab in my project. I'm exploring Merge Requests feature.
topic_branch
from master
.topic_branch
. topic_branch
to remote. master
to pull changes from topic_branch
. 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,
master
topic_branch
into master
master
In this case, there would be only 1 commit on master
.How to achieve this from GitLab ?
To prevent merge request authors from approving their own merge requests, enable Prevent author approval in your project's settings. If you enable approval rule overrides, merge requests created before a change to default approval rules are not affected. The only exceptions are changes to the target branch of the rule.
With --no-commit perform the merge and stop just before creating a merge commit, to give the user a chance to inspect and further tweak the merge result before committing. Note that fast-forward updates do not create a merge commit and therefore there is no way to stop those merges with --no-commit.
Merging your branch into master is the most common way to do this. Git creates a new commit (M) that is referred to as a merge commit that results from combining the changes from your feature branch and master from the point where the two branches diverged.
Your 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.
project
settings
(Note: This is NOT the profile settings available on the top right)General
tab.Merge Request Settings
sectionFast-Forward Merge
.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With