Git 钩子:"fatal: not a git repository:"

Git hook: "fatal: not a git repository:"

我的设置与我在新服务器上创建的设置类似,所以我知道 'principle works'。我有一个 Git post-receive 看起来像这样:

#!/bin/sh
git --work-tree="~/public_html" --git-dir="~/repo/website" checkout master -f

我检查了 10 次这些文件夹是正确的:-)

要设置 Git 存储库,我 运行 使用以下命令:

cd ~/repo/website
git init --bare
# Added content to post-receive file
chmod +x hooks/post-receive
# Verified that these permissions are set on the file

出于测试目的,我已将一些内容添加(推送)到存储库中。现在,当我尝试使用此命令执行测试命令时:

cd ~/repo/website && bash hooks/post-receive

我收到这个错误:

fatal: not a git repository: '~/repo/website'

然后我尝试完全删除存储库并从头开始制作它。但在第 4 次尝试时,我开始认为这不是前进的方向 ;-)

我在相关的 Whosebug 线程上读到可能 HEAD 文件已损坏。然而,它看起来不错 - 并且还与其他从头开始的尝试一起重新制作了四次。

出于部署原因,我需要设置工作树等。在其他服务器上使用相同的设置也能正常工作。

我希望有人知道如何解决这个问题。谢谢!

shell只有在单词开头时才会扩展~/。你有它在一个词的中间。

你应该写

#!/bin/sh
git --work-tree="$HOME/public_html" --git-dir="$HOME/repo/website" checkout -f master

最重要的是,由于 ~ 出现在双引号内,该字符被视为“被引用”并且将保持不变,无论 shell 是否可以猜到 --git-dir=有一些特殊的含义。