公司使用Gerrit代码审核,本地push代码只能提交到refs/for/[branch],所以使用git bash进行push时,需要使用如下命令
git push origin HEAD:refs/for/[branch]
我是使用Git Extensions操作Git,branch为develop,如果直接点击push按钮,就会报错
"C:\Program Files\Git\bin\git.exe" push --recurse-submodules=check --progress "origin" refs/heads/develop:refs/heads/develop
Enumerating objects: 24, done.
Counting objects: 100% (24/24), done.
Delta compression using up to 8 threads
Compressing objects: 100% (17/17), done.
Writing objects: 100% (17/17), 1.43 KiB | 730.00 KiB/s, done.
Total 17 (delta 14), reused 0 (delta 0)
remote: Resolving deltas: 100% (14/14)
remote: error: branch refs/heads/develop:
remote: To push into this reference you need 'Push' rights.
remote: User: walker4000
remote: Contact an administrator to fix the permissions
remote: Processing changes: refs: 1, done
! [remote rejected] develop -> develop (prohibited by Gerrit: not permitted: update)
error: failed to push some refs to 'ssh://10.10.10.10:2234/walker4000/index'
DonePress Enter or Esc to close console...
提示没有Push权限,因为点击Push按钮是提交到refs/heads/develop而不是refs/for/develop
解决方法1:
修改项目目录下的.git/config,将“merge = refs/heads/develop”改为“merge = refs/for/develop”
[branch "develop"]
remote = origin
merge = refs/for/develop
解决方法2:
a.点击Git Extensions的(版本:2.51.04)菜单“档案库\管理远程档案”,点击“默认拉取行为(获取以及合并)”选项卡
b.修改“默认合并”输入框的内容,将“develop”改为“refs/for/develop”,然后保存。
然后每次push代码直接点击 Push按钮就会自动选择refs/for/develop
点击”推送“按钮即可成功。
注:点击推送时会提示
你将要推送的这个分支对于远程端来说似乎是个新的分支。你确认要推动这个分支么
不用介意,每次都会提示,点击“是”即可,并不会在远程产生新的分支。