有没有办法在GIT中锁定一个分支 [英] Is there a way to lock a branch in GIT
问题描述
我有一个想法,即锁定一个来自用户的存储库,通过在GIT更新钩子中加入一个锁定脚本来推送文件,因为推送只能识别用户标识而不是分支。所以我可以锁定整个repo,这只是锁定一个目录。
I have an idea of locking a repository from users pushing files into it by having a lock script in the GIT update hook since the push can only recognize the userid as arguments and not the branches. So i can lock the entire repo which is just locking a directory.
有没有办法在GIT中锁定特定的分支?
Is there a way to lock a specific branch in GIT?
或者,有没有一种方法可以确定用户从哪个分支推送的代码被推送到哪个分支?
Or is there a way an Update Hook can identify from which branch the user is pushing and to which branch the code is pushed?
推荐答案
被推送到的分支是更新钩子的第一个参数。如果你想锁定分支 myfeature
来推送,这段代码(放在 hooks / update
中)
The branch being pushed to is the first parameter to the update hook. If you want to lock the branch myfeature
for pushing, this code (placed in hooks/update
) will do it:
#!/bin/sh
# lock the myfeature branch for pushing
refname="$1"
if [[ $refname == "refs/heads/myfeature" ]]
then
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
echo "You cannot push to myfeature! It's locked"
echo "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
exit 1
fi
exit 0
这篇关于有没有办法在GIT中锁定一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!