GitHub - 防止协作者使用 push -f [英] GitHub - prevent collaborators from using push -f

查看:55
本文介绍了GitHub - 防止协作者使用 push -f的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法防止强制推送到分支或存储库中?

Is there a way to prevent force push into a branch or repository?

我想阻止重要分支的历史记录被意外或有意改写.在更大的开发团队中,人们如何处理这个问题?

I want to stop important branches from having their history rewritten either accidentally or intentionally. How do people deal with this in larger development teams?

在我看来,理想情况下,可以锁定每个存储库的几个分支,并防止除了存储库所有者之外的所有人都对它们进行强制推送.

Ideally, in my view, would possible to lock few branches per repository, and prevent everyone, other than the repository owner from doing a force push into them.

推荐答案

通过 pre-receive 钩子使用 Git 很容易做到这一点.当然,这要求您实际上能够安装钩子,并且出于显而易见的原因,GitHub 不允许您上传任意可执行文件以在其服务器上运行:-)

This is easy to do with Git with a pre-receive hook. Of course, this requires that you are actually able to install hooks, and for obvious reasons, GitHub doesn't allow you to upload arbitrary executable files to run on their servers :-)

总的来说,Git 或任何分布式版本控制系统的工作流程是不允许其他人推送到您的存储库.相反,你从他们那里拉.这需要低得多的信任级别.所以,这将是解决方法 1:不要让他们推动,让他们分叉,然后从他们身上拉出来.这样,您就可以控制进入存储库的内容.

In general, the workflow with Git or really any distributed version control system, is that you don't allow other people to push to your repository. Instead, you pull from theirs. This requires a much lower level of trust. So, this would be workaround number 1: don't let them push, have them fork and then pull from them. That way, you can control what goes into your repository.

另一种解决方法是在您拥有的服务器上设置您自己的临时存储库,您可以在其中安装自己的 Git 挂钩.您可以配置一个 pre-receive 钩子,如果它不是快进和 post-receive 钩子,它会拒绝推送,它会自动将所有推送转发到 GitHub.当然,这意味着您首先失去了使用 GitHub 的许多好处.

Another workaround would be to set up your own staging repository on a server you own, where you can install your own Git hooks. You can configure a pre-receive hook which denies pushing if it's not a fast-forward and post-receive hook which automatically forwards all pushes to GitHub. Of course, this means that you lose many of the benefits of using GitHub in the first place.

作为第三种解决方法,您可以使用多个存储库.这是另外两种方法的组合:拥有一个您的协作者可以推送到的存储库和另一个只有您有权访问的存储库,您可以从第一个存储库中拉取.

As a third workaround, you could use multiple repositories. This is a combination of the two other approaches: have one repository that your collaborators can push to and another one that only you have access to, that you pull into from the first repository.

无论如何,您应该向 GitHub 提交功能请求(特别是如果您是付费客户!),因为这似乎是一个有用的功能.

At any rate, you should file a feature request with GitHub (especially if you are a paying customer!) since this seems to be a useful feature.

这篇关于GitHub - 防止协作者使用 push -f的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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