while read ref
do
#echo "Ref updated:"
#echo $ref -- would print something like example at top of file
result=`echo $ref | gawk -F' ' '{ print $3 }'`
if [ $result != "" ]; then
echo "Branch found: "
echo $result
case $result in
refs/heads/master )
git --work-tree=c:/temp/BLAH checkout -f master
echo "Updated master"
;;
refs/heads/testbranch )
git --work-tree=c:/temp/BLAH2 checkout -f testbranch
echo "Updated testbranch"
;;
* )
echo "No update known for $result"
;;
esac
fi
done
echo "Post-receive updates complete"
然而,我对这样做是否真的安全存有疑虑 :) 我绝不是Git专家,但我猜测Git可能会跟踪当前检出的分支头,并且这种方法可能有潜力令它感到困惑。
因此,有几个问题:
这样做安全吗?
是否有更好的方法:将我的基础仓库作为测试站点仓库(带相应的工作目录),然后让该仓库将更改推送到新的线上站点仓库,其具有相应的工作目录以适配线上站点基础?这样还可以让我将生产环境移到另一台服务器并保持部署链完整。
是否有我忽略的内容?使用Git管理网站时,是否有不同的、清晰的方法来区分测试和生产环境?
另外,在Vi的答案下,是否有一个很好的方法来处理删除而不会大量干扰文件系统?
谢谢, -Walt
PS-我想到的用于多个仓库(除非我听到更好的建议)的脚本如下:
sitename=`basename \`pwd\``
while read ref
do
#echo "Ref updated:"
#echo $ref -- would print something like example at top of file
result=`echo $ref | gawk -F' ' '{ print $3 }'`
if [ $result != "" ]; then
echo "Branch found: "
echo $result
case $result in
refs/heads/master )
git checkout -q -f master
if [ $? -eq 0 ]; then
echo "Test Site checked out properly"
else
echo "Failed to checkout test site!"
fi
;;
refs/heads/live-site )
git push -q ../Live/$sitename live-site:master
if [ $? -eq 0 ]; then
echo "Live Site received updates properly"
else
echo "Failed to push updates to Live Site"
fi
;;
* )
echo "No update known for $result"
;;
esac
fi
done
echo "Post-receive updates complete"
然后在 ../Live/$sitename 的仓库中(这些是“裸”仓库,在初始化后添加工作树),有一个基本的 post-receive 脚本:
git checkout -f
if [ $? -eq 0 ]; then
echo "Live site `basename \`pwd\`` checked out successfully"
else
echo "Live site failed to checkout"
fi