How to merge the Gerrit branch to another Gerrit branch
Asked Answered
H

3

43

I'm using Gerrit version 2.4.2. I have a branch master and I created a new branch, called newbranch. Then I pushed some changes to the remote (Gerrit's) newbranch. After verifying in Gerrit, I merged the changes to newbranch.

No, I want to merge the newbranch to master, send updates master (merged with changes from newbranch), and delete the newbranch branch.

I tried do this:

git fetch
git checkout master
git merge newbranch
git push origin master:refs/for/master

But Gerrit gives back this message:

 ! [remote rejected] master -> refs/for/master (no new changes)

What should I do?

Haemophilia answered 11/10, 2012 at 13:7 Comment(0)
M
38

This situation has been reported as a bug in Gerrit. Here's a solution/workaround from Gerrit's issue tracker:

To the best of my knowledge, you have 2 options currently -

  1. Force push to refs/heads. It is just a fast-forward, so in theory everything has already been reviewed and verified. There is no point in doing so again, so just skip that process and push to refs/heads rather than refs/for.

  2. Go ahead and create a merge commit. Use 'git merge --no-ff' - this will create a merge commit even though it isn't necessary in your fast-forward situation. Then the merge commit can be uploaded, reviewed, verified, and merged like normal.

My company tends to go with option 2. I'll close this as wontfix, but if you have any suggestions on how to do this better please let us know.

Muldrow answered 11/10, 2012 at 13:57 Comment(3)
What happens if someone submits a commit to master in the meantime the merge commit is being reviewed? Then I get a merge conflict, right? How can I fix this situation?Zeitgeist
@Zeitgeist In this case you would rebase the change on top of the recently updated master branch and amend the merge commit like you would any other.Escritoire
I updated the URL of the issue to the new one to which the old one redirects.Distinction
E
13

If the merge is a fast-forward merge, no object exists to push to gerrit, since a fast-forward is just moving the branch pointer.

You need to force the merge to create an object by avoiding a fast-forward:

git merge --no-ff
Eyewash answered 23/6, 2014 at 17:6 Comment(0)
Y
3

The following commands work perfectly.

git checkout master
git merge --no-ff newbranch

You can save with the default commit message. Make sure, the change id has been generated. You can use the following command to make sure.

git commit --amend

Then push with the following command.

git push origin HEAD:refs/for/refs/heads/master

You might encounter an error message like the below.

! [remote rejected] HEAD -> refs/for/refs/heads/master (you are not allowed to upload merges)

To resolve this, the gerrit project admin has to create another reference in gerrit named 'refs/for/refs/heads/master' or 'refs/for/refs/heads/*' (which will cover all branches in future). Then grant 'Push Merge Commit' permission to this reference and 'Submit' permission if required to Submit the GCR.

Now, try the above push command again, and it should work.

Credits:

https://github.com/ReviewAssistant/reviewassistant/wiki/Merging-branches-in-Gerrit

https://mcmap.net/q/54549/-gerrit-remote-rejected-you-are-not-allowed-to-upload-merges-even-though-i-allowed-quot-push-merge-commit-quot

Yehudi answered 5/4, 2019 at 12:8 Comment(1)
It is strange, but in my case git merge --no-ff doesn't work, bur git merge --no-ff branchName works goodQuadricycle

© 2022 - 2024 — McMap. All rights reserved.