gpt4 book ai didi

接收后 Hook 中的 Git checkout : "operation must be run in a work tree"

转载 作者:太空狗 更新时间:2023-10-29 14:19:18 26 4
gpt4 key购买 nike

为了使用 git 远程更新我的网站,我在共享主机帐户的根目录下创建了一个裸 git 存储库以及以下接收后 Hook :

#!/bin/sh
export GIT_WORK_TREE=/public_html
git checkout -f

这最初按预期工作:将我的更改推送到远程存储库时,接收后 Hook 被触发,文件被 check out 到/public_html 文件夹。

但是,我现在在 checkout 时收到“致命:此操作必须在工作树中运行”错误。我不知道为什么现在会出现此错误,因为我没有对我的设置进行任何更改。

我卡住了。对我来说,这应该可以正常工作(而且确实可以),除非我完全误解了 git 的工作原理。我一直在寻找与我类似的问题,但到目前为止还没有找到任何有用的东西。

如果我知道应该去哪里,我将不胜感激。

最佳答案

Hook 在 .git 目录中运行。

我在钩子(Hook)中的 git checkout 之前使用了 cd .. 作为一个简单的解决方法。

如果 .git 存储库与 checkout 位置完全不相交,您也可以想象

cd /path/to/checkout
GIT_DIR=/path/to/repo/.git git checkout -f

关于接收后 Hook 中的 Git checkout : "operation must be run in a work tree",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23955687/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com