按分支使用 Git 作为部署工具时出现问题
我正在尝试创建一个更新后脚本并使用 git 作为远程服务器上的部署工具。
我的更新后脚本看起来像这样
git update-server-info
for ref in $@;do
echo $ref
if [ "$ref" = "refs/heads/production" ]
then
ssh [email protected] 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 [email protected] GIT_DIR=/home/www/test/.git GIT_WORK_TREE=/home/www/test git checkout -f production
I am trying to create a post update script and use git as a deployment tool on a remote server.
My post-update script looks something like this
git update-server-info
for ref in $@;do
echo $ref
if [ "$ref" = "refs/heads/production" ]
then
ssh [email protected] GIT_WORK_TREE=/home/www/test git checkout -f production
fi
done
However, when I run that, an error comes back that says:
Not a git repository (or any of the parent directories): .git
Which doesn't make any sense because I am able to run git commands from within the directory over ssh.
Is there something else that I need to be doing in my post-update script?
Solution
I added the GIT_DIR
variable, so now my command looks like:
ssh [email protected] GIT_DIR=/home/www/test/.git GIT_WORK_TREE=/home/www/test git checkout -f production
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还需要设置
GIT_DIR
环境变量 - 尝试以下操作:关于
GIT_DIR
和GIT_WORK_TREE
的规则(及其等效项- -git-dir=<>
和--work-tree=<>
) 对我来说是如此违反直觉,以至于我现在制定了一条规则,如果我'如果设置其中之一,我应该同时设置两者,并确保它们都设置为绝对路径。You also need to set the
GIT_DIR
environment variable - try the following:The rules about
GIT_DIR
andGIT_WORK_TREE
(and their equivalents,--git-dir=<>
and--work-tree=<>
) are so counter-intuitive to me that I now make it a rule that if I'm setting either one of them, I should set both, and furthermore make sure that they're both set to absolute paths.