这个想法是使用
post-receive hook
在服务器上设置强制
(
-f
选项)在特定目录中签出
您可以使用
--work-tree=/path/
选项
示例代码(以文件形式保存在服务器上的裸机上
hooks/post-receive
执行位设置)由
this Gist
可以是:
#!/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