Gerrit代码审查

公司代码库部分 库使用了 Gerrit
对整个东东不太熟悉
相关提交命令整理在这里做备忘
相关文档看这里吧

https://gerrit-review.googlesource.com/Documentation/user-upload.html#_git_push

提交代码的操作

git push 仓库地址 HEAD:refs/for/分支名
git push ssh://sshusername@hostname:29418/projectname HEAD:refs/for/branch
git push origin HEAD:refs/for/mybranch

如果需要code review,直接push,则会产生问题

$git push origin master

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

refs/for的含义

表示本次提交需要review ,只有服务端进行review后才会合入仓库.否则提交对别人是不可见的

如果不需要review而进行提交,则需要使用 refs/heads/

refs/for/ 和refs/heads/的区别

提交所有分支

git push origin refs/heads/*:refs/for/*

修改.git/config文件,添加push时的引用

[remote "origin"]
        url = ssh://chenjianhua@127.0.0.1:29418/hello1
        fetch = +refs/heads/*:refs/remotes/origin/*
        push = HEAD:refs/for/*

git push 报错:missing Change-Id in commit message footer

使用gerrit后,提交代码会出现如下截图问题:
在这里插入图片描述

remote: Processing changes: refs: 1, done    
remote: ERROR: missing Change-Id in commit message footer
remote: 
remote: Hint: To automatically insert Change-Id, install the hook:
remote:   gitdir=$(git rev-parse --git-dir); scp -p -P 29418 root@ubuntu:hooks/commit-msg ${gitdir}/hooks/
remote: And then amend the commit:
remote:   git commit --amend
remote: 
To ssh://member@127.0.0.1:29418/hello1
 ! [remote rejected] master -> refs/for/master (missing Change-Id in commit message footer)
临时解决:

step1:把上面红色的那条gitidir复制下来执行下:
在这里插入图片描述
step2:执行下面的命令会添加change_id

  git commit --amend

step3:然后推送代码到服务器上

  git push origin HEAD:refs/for/$branch_name

上面这个情况主要针对本地刚下载的仓库,第一次提交会出现这个情况,只需要执行一次,以后再该仓库提交就不用执行了,说白了就是这个commit-msg是局部的,只对当前仓库生效。

还有另一种情况也会有这种报错,可以看这里

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值