本文介绍了如何在不使用Gitolite的情况下防止git中远程分支删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以阻止删除远程分支吗?

Is there any way to block deletion of remote branches?

我想阻止远程分支的删除,但是正常的流程(如代码检查和检出)应该可以正常工作!

I want to block deletion of remote branches but normal flow like code checking and check out should work fine!!

不使用乙醇钠!有可能吗?

without using gitolite! is it possible ?

请帮助!

推荐答案

是的,有可能.只需添加一个合适的服务器端git钩子即可.

Yes, it is possible. Just add a suitable server side git hook.

您可能想使用预接收挂钩.有关详细信息,请参见此处此处.

You probably want to use a pre-receive hook. For details have a look at here or here.

示例:

#create repositories
git init a
git init --bare b

#add the hook in "b"
echo -e '#!/usr/bin/bash\nread old new ref\ntest $new != 0000000000000000000000000000000000000000' >>b/hooks/pre-receive
chmod +x b/hooks/pre-receive

#create a commit in "a"
cd a
echo foo >test
git add .
git commit -m testcommit

#push it to "b"
git push ../b master

#try to delete remote branch
git push ../b :master

这篇关于如何在不使用Gitolite的情况下防止git中远程分支删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 13:05