Reputation: 15755
I have two branches master
and release
at gitlab.
At release branch, I hope it will only have commit message like: v0.1.0, v0.1.1.
Say after I finished developed v0.1.0, I have have several feature and bugfix commits in master
say
c1. bugfix1
c2. feature1
c3. feature2
I will create merge request in gitlab from master
to release
, but I hope to make these three commits into one v0.1.0
, and squash c1 c2 c3.
Now , in my existing settings, I will have 4 commit messages:
Merge breanch 'master' into release
c1
c2
c3
Is there a way to squash it when I approve at gitlab so that there message will squash into:
v0.1.0
Please note that these two branch are all proteced branches, and if possible I hope there will be NO git command on release
and master
branch , and only gitlab operations
Upvotes: 4
Views: 13964
Reputation: 61
To squash manually Go to your master branch or the branch you want to merge
git reset --soft HEAD~7 (number of commits from the head you want to squash)
git commit -m "squashed commit"
git push
This will reset to a number of commits that were in the master branch. And One single commit will be created with all the changes. PS: If you are facing an automatic squash error you can use this.
Upvotes: 1
Reputation: 881
In case you are seeing this message on GitLab graphical interface, like this:
Just follow these steps from your MR link:
Edit > Merge options: uncheck "Squash commits when merge request is accepted" option.
After that, merge should happen on Gitlab.
Upvotes: -1
Reputation: 9898
git checkout release
git merge --squash master
git commit -m "Suitable Message of your choice"
This will take all the commits from the master
branch, squash them into 1 commit and then merge it with your release
branch.
Upvotes: 5
Reputation: 8345
The merge commit is only one commit, but it seems you have fallen into the "fast forward" trap. That is, on your merge, git
has decided that master
is part of the direct ancestry of release
, and then just "fast forwarded" your changes on top of release
. This, then, looks like what you describe.
To solve this, add the --no-ff
option on your merge:
git checkout release
git merge --no-ff master
You will, then, have exactly one commit on your release
branch; you can edit the commit message to contain your release version.
Upvotes: 2
Reputation: 698
You can use git rebase to squash commits.
In your case, it should be git rebase -i HEAD~3.
See http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
Upvotes: 1