git 如何将 Gerrit 分支合并到另一个 Gerrit 分支
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12840279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to merge the Gerrit branch to another Gerrit branch
提问by Alan Shen
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
.
我正在使用 Gerrit 2.4.2 版。我有一个分支master
,我创建了一个新分支,名为 newbranch
. 然后我将一些更改推送到遥控器 (Gerrit's) newbranch
。在 Gerrit 中验证后,我将更改合并到newbranch
.
No, I want to merge the newbranch
to master
, send updates master
(merged with changes from newbranch
), and delete the newbranch
branch.
不,我想合并newbranch
to master
,发送更新master
(与来自 的更改合并newbranch
),然后删除newbranch
分支。
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:
但是 Gerrit 返回了这条消息:
! [remote rejected] master -> refs/for/master (no new changes)
What should I do?
我该怎么办?
回答by Michael Sims
This situation has been reported as a bug in Gerrit. Here's a solution/workaround from Gerrit's issue tracker:
这种情况已被报告为 Gerrit 中的一个错误。这是Gerrit 问题跟踪器的解决方案/解决方法:
To the best of my knowledge, you have 2 options currently -
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.
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.
据我所知,您目前有 2 个选择 -
强制推送到裁判/负责人。这只是一个快进,所以理论上一切都已经过和验证。再次这样做没有意义,所以只需跳过该过程并推送到 refs/heads 而不是 refs/for。
继续并创建一个合并提交。使用 'git merge --no-ff' - 这将创建一个合并提交,即使在您的快进情况下它不是必需的。然后可以像往常一样上传、、验证和合并合并提交。
我的公司倾向于使用选项 2。我将其关闭为 wontfix,但如果您有任何关于如何更好地执行此操作的建议,请告诉我们。
回答by Sogger
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.
如果合并是快进合并,则不存在推送到 gerrit 的对象,因为快进只是移动分支指针。
You need to force the merge to create an object by avoiding a fast-forward:
您需要通过避免快进来强制合并以创建对象:
git merge --no-ff
回答by Sankaran Srinivasan
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.
您可以使用默认提交消息进行保存。确保已生成更改 ID。您可以使用以下命令来确定。
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.
为了解决这个问题,gerrit 项目管理员必须在 gerrit 中创建另一个名为 'refs/for/refs/heads/master' 或 'refs/for/refs/heads/*' 的引用(将来会覆盖所有分支)。然后,如果需要提交 GCR,则授予此引用的“推送合并提交”权限和“提交”权限。
Now, try the above push command again, and it should work.
现在,再次尝试上面的 push 命令,它应该可以工作。
Credits:
学分:
https://github.com/ReviewAssistant/reviewassistant/wiki/Merging-branches-in-Gerrit
https://github.com/ReviewAssistant/reviewassistant/wiki/Merging-branches-in-Gerrit