关于refs/for 和 refs/heads:

1.     这个不是git的规则,而是gerrit的规则,

2.     Branches, remote-tracking branches, and tags等等都是对commite的引用(reference),引用都以 “refs/……”表示. 比如remote branch: origin/git_int(=refs/remotes/origin/git_int), local tag: v2.0(=refs/tags/v2.0), local branch: git_int(=refs/heads/git_int)…

3.     简单点说,就是refs/for/mybranch需要经过code review之后才可以提交;refs/heads/mybranch不需要code review

(since you want to directly push into the branch, rather than create code reviews. Pushing to refs/for/* creates code reviews which must be approved and then submitted. Pushing to refs/heads/* bypasses review entirely, and just enters the commits directly into the branch. The latter does not check committer identity, making it appropriate for importing past project history)

如果需要code review,直接push

$ git push origin master

那么就会有“! [remote rejected] master -> master (prohibited by Gerrit)”的错误信息!

而这样push就没有问题:

$git push origin HEAD:refs/for/mybranch

下面一段是对“refs/for”更详细的描述:

The documentation for Gerrit explains that you push to the "magical refs/for/'branch' ref using any Git client tool".

This 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.

Internally, Gerrit has it's own implementation for the Git and SSH stacks. This allows it to provide the "magical" refs/for/<BRANCH> refs.

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.

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.

转载自: http://lishicongli.blog.163.com/blog/static/146825902013213439500/

git + gerrit push 代码问题的更多相关文章

  1. Heroku空项目 Git本地Push代码错误 以及 Heroku Web启动错误

    在Eclipse下建了一个"Blank Heroku App", 然后将自己写好的JS Web练习代码直接复制放到了这个空项目下, 由于Eclipse下的git工具不太会用, 导致 ...

  2. 初学git:用git bash往github push代码

    对于我来说,最开始使用github主要是为了使用它的pages功能展示demo.其实这些都是用Github for Windows push上去的,图形化界面的客户端使用确实简单,但是逼格不够,好吧其 ...

  3. git解决修改代码后无法push的问题failed to push some refs to 'ssh://git@xxx.xxx.xx/xx.git'

    今天在使用git提交代码的时候,犯了个很低级的错误,按照一切流程当我add并commit提交代码,最后使用push到远程仓库, 接下来奇怪的事情发生了,push之后,查看远程仓库代码并没有发现提交记录 ...

  4. (诊断)解决GitHub使用双因子身份认证“Two-Factor Athentication”后无法git push 代码的“fatal: Authentication failed for ...”错误

    在GitHub上采取双因子身份认证后,在git push 的时候将会要求填写用户的用户名和密码,用户名就是用户在GitHub上申请的用户名,但是密码不是普通登录GitHub的密码. 一旦采取双因子身份 ...

  5. Git之Github使用(一):Push代码到Github

    Git之Github使用(一):Push代码到Github 热度 2已有 58 次阅读2016-8-26 17:56 |个人分类:常见问题|系统分类:移动开发| 互联网, commit, status ...

  6. git 使用https方式进行 pull、push代码免密

    由于网络原因我用ssh方法拉取代码每次都提示远程服务连接失败,因此我用了https方式去拉去代码. 这种方式拉取代码每次操作都要输入密码,为了解决这个问题做了一下操作: 在命令行输入 git conf ...

  7. sourceTree+gerrit管理代码

    第一次接触gerrit,会对这种代码管理方式非常排斥,尤其是习惯了用sourceTree配合git进行代码管理的同学.不爽归不爽,代码还得写,我们的目标是让开发过程爽起来. 关于gerrit的知识,移 ...

  8. 配置git同时push到两个远端库的简单方法

    最近在写一个开源的论坛系统,在发布代码时选择了github和coding这两个平台,我手懒,不想敲两次git push了,所以说突然有了一个很奇怪的需求:用一条git push同时push到两个远端代 ...

  9. 15分钟学会使用Git和远程代码库

    git是个了不起但却复杂的源代码管理系统.它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作.让我们诚实一记吧:Git是复杂的,我们不要装作它不是.但我仍然会试图教会你用(我的)基本 ...

随机推荐

  1. freemarker中间split字符串切割

    freemarker中间split字符串切割 1.简易说明 split切割:用来依据另外一个字符串的出现将原字符串切割成字符串序列 2.举例说明 <#--freemarker中的split字符串 ...

  2. error: openssl/md5.h: No such file or directory

    出现:error: openssl/md5.h: No such file or directory 原因是openssl-devel没有安装,运行: yum install libssl-dev 就 ...

  3. Go语言并发

    Go语言并发机制初探   Go 语言相比Java等一个很大的优势就是可以方便地编写并发程序.Go 语言内置了 goroutine 机制,使用goroutine可以快速地开发并发程序, 更好的利用多核处 ...

  4. python生成测试图片

    直接代码 import cv2.cv as cv saveImagePath = 'E:/ScreenTestImages/' colorRed = [0,0,255] colorGreen = [0 ...

  5. CSS动作

    5.过渡 tansition  (由一个状态过渡到另外一个状态的过程)             transition            过渡                 参数1:        ...

  6. Android开发之 shape的使用

    android shape的使用 shape用于设定形状,能够在selector,layout等里面使用,有6个子标签,各属性例如以下: <?xml version="1.0" ...

  7. 抛砖引玉 【镜像控件】 WPF实现毛玻璃控件不要太简单

    原文:抛砖引玉 [镜像控件] WPF实现毛玻璃控件不要太简单 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Vblegend_2013/articl ...

  8. 【每日一句】make a scene

    scene有场面.场景的意思,只是make a scene可不是指做场面.scene还有还有一个意思,指很生气而大吵大闹(的情景),因此make a scene就是指某人情绪失控发脾气.如今一起从以下 ...

  9. QWidget居中显示(qt窗口坐标原点是在”左上角”的,有图)

    转载请说明出处, 并附上原文链接http://blog.csdn.net/qq907482638/article/details/72189014. 问题描述 在Qt学习过程中,在让QDialog居中 ...

  10. WPF 线程:使用调度程序构建反应速度更快的应用程序

    原文:WPF 线程:使用调度程序构建反应速度更快的应用程序 作者:Shawn Wildermuth 原文:http://msdn.microsoft.com/msdnmag/issues/07/10/ ...