这个想法是在服务器上使用 a并在特定目录中post-receive hook
设置强制(选项)签出-f
您可以使用选项在特定工作目录中获取结帐--work-tree=/path/
...
由此 Gisthooks/post-receive
改编的示例代码(作为设置了执行位的文件保存在服务器上的裸存储库中)可以是:
#!/bin/bash
echo '--- --- --- --- --- --- --- --- --- --- ---'
echo 'Deploying site...'
echo '--- --- --- --- --- --- --- --- --- --- ---'
if ! [ -t 0 ]; then
read -a ref
fi
IFS='/' read -ra REF <<< "${ref[2]}"
branch="${REF[2]}"
# Master Branch
if [ "PROD" == "$branch" ]; then
git --work-tree=/path/to/public/PROD checkout -f $branch
echo 'Changes pushed to production site'
fi
# Stage Branch
if [ "STAGE" == "$branch" ]; then
git --work-tree=/path/to/public/STAGE checkout -f $branch
echo 'Changes pushed to stage site'
fi
# Development Branch
if [ "DEV" == "$branch" ]; then
git --work-tree=/path/to/public/DEV checkout -f $branch
echo 'Changes pushed to dev site'
fi
echo '--- --- --- --- --- --- --- --- --- --- ---'
结帐的另一个可能的语法是
GIT_WORK_TREE=/path/to/test/site git checkout -f