有没有办法阻止代码推送直接掌握?我尝试在.git / hooks / update中添加一个脚本:
#!/bin/sh if [ $USER != "git-repo-admin" ]; then if [ "$1" == refs/heads/master ]; then echo "Manual pushing to this repo is restricted" exit 1 fi fi
但这不行 – 每个人都可以推.我只想允许特定用户推送以阻止他人.
解决方法
原始脚本是完美的,我只需要将其从.git / hooks / update.sample重命名为远程服务器上的.git / hooks / update,并确保它是可执行的.
#!/bin/sh if [ $USER != "git-repo-admin" ]; then if [ "$1" == refs/heads/master ]; then echo "Manual pushing to this repo is restricted" exit 1 fi fi