blog icon indicating copy to clipboard operation
blog copied to clipboard

Gitlab强制推送提示"You are not allowed to force push code to a protected branch on this project."

Open shaobeichen opened this issue 7 years ago • 4 comments

timg

场景还原:公司上新网站,需要进行百度等平台审查,其中不能出现敏感字眼等,所以将网站中的字词问题修改了,本来的意思就是现在随便修改,之后再Gitlab上回滚即可,现在审查过了,需要进行回滚,可是回滚时强推出现了没有权限的问题,明明权限已经是master了,但还是强推不了。

强制推送命令

$ git push -u origin master -f

推送命令后出现了这样的情况

E:\xxx>git push -f origin master
Password for 'http://[email protected]':
Total 0 (delta 0), reused 0 (delta 0)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To http://git.xxx.cn/xxx/xxx
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://[email protected]/xxx/xxx.git'

"GitLab: You are not allowed to force push code to a protected branch on this project." 提示没有权限强制推送

后来在网上进行一番搜索,发现了问题

snipaste_2018-06-19_11-41-08

就是这里,左边的意思是受保护的分支,受保护的分支不允许进行强制推送,解除掉受保护的分支即可,UnProtect解除保护,然后再次进行强制推送命令$ git push -u origin master -f

推完之后再回到这里进行重新保护master分支,选择分支,点击Protect即可

image

shaobeichen avatar Jun 19 '18 03:06 shaobeichen

学习力 不错

mullerhai avatar Jul 12 '19 03:07 mullerhai

这不是强推不强推的事儿,这个是对 push 的限制,加上 protect 就不能 push,去掉就能 push,和 force 与否没有一毛钱关系

hnl1 avatar Jan 16 '20 03:01 hnl1

这不是强推不强推的事儿,这个是对 push 的限制,加上 protect 就不能 push,去掉就能 push,和 force 与否没有一毛钱关系

不是,错了,@LeachZhou 说的是对的。刚刚我实验了。

只要一个分支加到 protect 中,就不能再 force push 了。此时能不能 push 是由前面的选项来决定的,选择了你的身份能 push,那就能 push;选择了能 merge,那就能 merge。

hnl1 avatar Jan 16 '20 03:01 hnl1

确实是因为保护分支的设置引起的。但是在idea中操作只显示推送拒绝没有显示原因,如果使用命令的话会有提示你不能强制推送。然后我找到了gitlab的保护分支设置,它的描述是如果设置了保护分支则默认不允许强制推送。 image

chf-gh avatar Nov 14 '20 17:11 chf-gh