简体   繁体   English

在GIT中,如何防止人们更改或删除已经推送的提交?

[英]In GIT, how can I prevent people from changing or removing commits that have already been pushed?

We recently had an intern run "git reset --hard" and accidentally undo a lot of work on our main GIT repo. 我们最近有一个实习生“git reset --hard”,并且不小心撤消了我们主要GIT仓库的大量工作。 We are in the process of recovering the work, but I want to make sure nothing like this ever happens again. 我们正在恢复工作,但我想确保这样的事情再也不会发生。

I know there are a lot of questions about this, but they all seem to be about recovering rather than prevention. 我知道有很多关于此的问题,但它们似乎都是关于恢复而不是预防。 Is there any way I can prevent pushes to our main repo that alter or remove commits that have already been pushed? 有什么方法可以阻止推送到我们的主仓库改变或删除已被推送的提交? Is there a config setting or maybe a push hook that will do the job? 是否有配置设置或推送挂钩可以完成这项工作?

There are 2 configuration options you can set on your central (bare) repo to help prevent this problem: 您可以在中央(裸)repo上设置2个配置选项 ,以帮助防止出现此问题:

receive.denyNonFastForwards
receive.denyDeletes

The first option requires that all pushes add history only. 第一个选项要求所有推送仅添加历史记录。 A git reset followed by a git push would be denied. git reset后跟git push将被拒绝。

The second closes a loop-hole where someone could delete a remote branch with git push <origin> :<branch-to-delete> and then push again with a normal git push and whatever changes they wanted. 第二个关闭一个循环漏洞,有人可以使用git push <origin> :<branch-to-delete>删除远程分支,然后使用正常的git push和他们想要的任何更改再次git push

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM