我正在尝试创建一个更新后脚本,并使用git作为远程服务器上的部署工具。
我的更新后脚本看起来像这样
git update-server-info
for ref in $@;do
echo $ref
if [ "$ref" = "refs/heads/production" ]
then
ssh git@myProductionServer.com GIT_WORK_TREE=/home/www/test git checkout -f production
fi
done
然而,当我运行时,会出现一个错误:
Not a git repository (or any of the parent directories): .git
这没有任何意义,因为我能够通过ssh从目录中运行git命令。
我在更新后的脚本中还需要做些什么吗?
解决方案
我添加了GIT_DIR
变量,所以现在我的命令如下:
ssh git@myProductionServer.com GIT_DIR=/home/www/test/.git GIT_WORK_TREE=/home/www/test git checkout -f production
答案 0 :(得分:3)
您还需要设置GIT_DIR
环境变量 - 请尝试以下操作:
ssh git@myProductionServer.com GIT_WORK_TREE=/home/www/test GIT_DIR=/home/www/test/.git git checkout -f production
关于GIT_DIR
和GIT_WORK_TREE
(及其等价物,--git-dir=<>
和--work-tree=<>
)的规则对我来说非常违反直觉,我现在规定如果我要设置其中一个,我应该设置两个,并进一步确保它们都设置为绝对路径。