本文介绍了有没有办法配置git存储库来拒绝'git push --force'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以阻止存储库上的 git push --force '(仅在master分支上)?



假设我有远程git存储库并执行:


  • ' git push '到'master'。它工作。

  • ' git push --force '到'branch-1'。它可以工作。

  • ' git push --force '到'master'。它被拒绝。



是否有可能?

答案和建议。

BR,
Dawid。

解决方案

设置配置变量:

  receive.denyNonFastForwards 
receive.denyDeletes

将防止任何'强制'推送在所有分行工作。



如果你想要更好的预分支控制,那么你将不得不在远程仓库上使用'钩子',可能是'更新'钩子。



有一个示例更新钩子'update-paranoid'可能会在'contrib'文件夹中的git分发中满足你需要的(和更多)。


I was wondering is there a way to prevent 'git push --force' on a repository (only on master branch)?

Assume I have remote git repository and do:

  • 'git push' to 'master'. It works.
  • 'git push --force' to 'branch-1'. It works.
  • 'git push --force' to 'master'. It is rejected.

Is it even possible?

Thanks for any answers and suggestions.

BR,Dawid.

解决方案

Setting the configuration variables:

receive.denyNonFastForwards
receive.denyDeletes

will prevent any 'forced' pushes from working across all branches.

If you want finer pre-branch control then you will have to use a 'hook' on the remote repository, probably the 'update' hook.

There is a sample update hook called 'update-paranoid' that probably does what you need (and more) in the git distribution in the 'contrib' folder.

gitweb link

这篇关于有没有办法配置git存储库来拒绝'git push --force'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-16 11:39
查看更多