问题描述
有没有办法阻止强制推入分支或存储库?我想阻止重要的分支机构无意或故意地重写其历史记录。人们如何在更大的开发团队中处理这个问题?
理想情况下,在我看来,每个存储库都可以锁定很少的分支机构,并防止除存储库所有者从这里开始强行推送。
使用Git和接收
钩子。当然,这要求你真的可以安装钩子,并且出于显而易见的原因,GitHub不允许你上传任意可执行文件在其服务器上运行: - )
一般来说,使用Git或任何分布式版本控制系统的工作流程是,您不允许其他人推送到您的存储库。相反,你拉他们的。这需要低得多的信任。所以,这将是解决方法1:不要让他们推,让他们叉,然后从他们拉。这样,您可以控制进入您的存储库的内容。
另一个解决方法是在您拥有的服务器上设置自己的临时存储库,您可以在其中安装自己的临时存储库Git挂钩。你可以配置一个预接收
挂钩,如果它不是快进而拒绝推送,并且 post-receive
挂钩自动转发所有推送到GitHub。当然,这意味着您首先会失去使用GitHub的许多好处。
作为第三种解决方法,您可以使用多个存储库。这是另外两种方法的组合:有一个仓库可以让你的合作者推送到另一个仓库,而另一个仓库只有你有权访问,你从第一个仓库进入。
无论如何,您应该向GitHub提交功能请求(特别是如果您是付费客户!),因为这似乎是一个有用的功能。
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.
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 :-)
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.
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.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!