如何强制推送到 Gitlab [英] How to force push to Gitlab

查看:142
本文介绍了如何强制推送到 Gitlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

git push --force gitlab master枚举对象:50,完成.计数对象:100% (50/50),完成.使用多达 8 个线程的 Delta 压缩压缩对象:100% (29/29),完成.写入对象:100% (40/40),12.22 KiB |4.07 MiB/s,完成.总计 40 个(增量 26),重复使用 18 个(增量 11)远程:GitLab:您不允许将代码强制推送到此项目的受保护分支.到 gitlab.com:xxx/yyyy.git![远程拒绝] 主人->主人(预收挂钩被拒绝)错误:未能将一些参考资料推送到 'git@gitlab.com:xxx/yyyy.git'

我应该怎么做才能将我的提交推送到 Gitlab?我使用了几个遥控器,其他遥控器都可以,我能完成

git push --force some_other_remote master

解决方案

来自

在那里,您可以点击任一:

  • 允许强制推送"切换按钮,或
  • 橙色的取消保护按钮

对于您要强制推送到的分支,例如 master.

如果您不想浏览导航栏,也可以填写此 URL 模板:

https://gitlab.com/<USERNAME>/<PROJECTNAME>/settings/repository#js-protected-branches-settings

并将 <USERNAME><PROJECTNAME> 分别替换为您的特定用户名和项目名称.

注意,允许强制推送"按钮可能比取消选择 Unprotect 按钮更受欢迎,因为分支保护可以为您提供额外的安全性,避免意外删除分支.但任何一个选项似乎都有效.

更多帮助:

git push --force gitlab master                                                                                  
Enumerating objects: 50, done.
Counting objects: 100% (50/50), done.
Delta compression using up to 8 threads
Compressing objects: 100% (29/29), done.
Writing objects: 100% (40/40), 12.22 KiB | 4.07 MiB/s, done.
Total 40 (delta 26), reused 18 (delta 11)
remote: GitLab: You are not allowed to force push code to a protected branch on this project.
To gitlab.com:xxx/yyyy.git
 ! [remote rejected]     master -> master (pre-receive hook declined)
error: failed to push some refs to 'git@gitlab.com:xxx/yyyy.git'

What should I do to push my commits to Gitlab? I use several remotes, and other remotes are OK and I was able to finish

git push --force some_other_remote master      

解决方案

From the official documentation on dealing with Protected Branches:

  1. Navigate to your project’s Settings ➔ Repository
  2. Scroll to find the Protected branches section.
  3. From the Branch dropdown menu, select the branch you want to protect and click Protect.

Following the steps above, you should be greeted with a box similar to this one below.

There, you can click either:

  • "Allowed to force push" toggle button, or
  • the orange Unprotect button

for the branch you want to force push to, e.g., master.

If you don't want to navigate through the navigation bars, you can also fill out this URL template:

https://gitlab.com/<USERNAME>/<PROJECTNAME>/settings/repository#js-protected-branches-settings

and replace <USERNAME> and <PROJECTNAME> with your specific username and project name, respectively.

Note, the "Allowed to force push" button is probably favored over un-selecting the Unprotect button because branch protection gives you additional safety from accidentally deleting your branch. But either option appears to work.

More help:

这篇关于如何强制推送到 Gitlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆