为什么使用 git push gerrit HEAD:refs/for/master 而不是 git push origin master
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10461214/
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
Why is git push gerrit HEAD:refs/for/master used instead of git push origin master
提问by Shrayas
I've just started using gerrit and I want to know why we need to do git push gerrit HEAD:refs/for/master
instead of doing git push origin master
我刚刚开始使用 gerrit,我想知道为什么我们需要做git push gerrit HEAD:refs/for/master
而不是做git push origin master
If I do git push origin master
I get the error saying ! [remote rejected] master -> master (prohibited by Gerrit)
如果我这样做,git push origin master
我会收到错误消息! [remote rejected] master -> master (prohibited by Gerrit)
回答by simont
The documentation for Gerrit, in particular the "Push changes"section, explains that you push to the "magical refs/for/'branch'
ref using any Git client tool".
Gerrit 的文档,特别是“推送更改”部分,解释了您refs/for/'branch'
使用任何 Git 客户端工具推送到“神奇的引用”。
The following image is taken from the Intro to Gerrit. When you push to Gerrit, you do git push gerrit HEAD:refs/for/<BRANCH>
. This pushes your changes to the staging area(in the diagram, "Pending Changes"). Gerrit doesn't actually have a branch called <BRANCH>
; it lies to the git client.
下图取自Intro to Gerrit。当您推送到 Gerrit 时,您会这样做git push gerrit HEAD:refs/for/<BRANCH>
。这会将您的更改推送到暂存区(在图表中,“待定更改”)。Gerrit 实际上并没有一个名为<BRANCH>
;的分支。它对 git 客户端说谎。
Internally, Gerrit has its own implementation for the Git and SSH stacks. This allows it to provide the "magical" refs/for/<BRANCH>
refs.
在内部,Gerrit 有自己的 Git 和 SSH 堆栈实现。这允许它提供“神奇”的refs/for/<BRANCH>
参考。
When a push request is received to create a ref in one of these namespaces Gerrit performs its own logic to update the database, and then lies to the client about the result of the operation. A successful result causes the client to believe that Gerrit has created the ref, but in reality Gerrit hasn't created the ref at all. [Link - Gerrit, "Gritty Details"].
当收到推送请求以在这些命名空间之一中创建 ref 时,Gerrit 执行其自己的逻辑来更新数据库,然后向客户端谎报操作结果。一个成功的结果会让客户相信 Gerrit 已经创建了 ref,但实际上 Gerrit 根本没有创建 ref。[链接 - Gerrit,“坚韧不拔的细节”]。
After a successful patch (i.e, the patch has been pushed to Gerrit, [putting it into the "Pending Changes" staging area], reviewed, and the review has passed), Gerrit pushes the change from the "Pending Changes" into the "Authoritative Repository", calculating which branch to push it into based on the magic it did when you pushed to refs/for/<BRANCH>
. This way, successfully reviewed patches can be pulled directly from the correct branches of the Authoritative Repository
.
补丁成功后(即已将补丁推送到 Gerrit,[放入“Pending Changes”暂存区],审核,审核通过),Gerrit 将变更从“Pending Changes”推送到“权威存储库”,根据推送到refs/for/<BRANCH>
. 这样,可以直接从Authoritative Repository
.
回答by Sean Murphy
In order to avoid having to fully specify the git push command you could alternatively modify your git config file:
为了避免必须完全指定 git push 命令,您也可以修改您的 git 配置文件:
[remote "gerrit"]
url = https://your.gerrit.repo:44444/repo
fetch = +refs/heads/master:refs/remotes/origin/master
push = refs/heads/master:refs/for/master
Now you can simply:
现在您可以简单地:
git fetch gerrit
git push gerrit
This is according to Gerrit
这是根据Gerrit 的说法