当使用更新后钩子对另一个回购执行‘ git pull’时,会得到’致命的: 不是 git 存储库:’

我是新来的,所以我道歉(请纠正我) ,如果我在这里误用术语,但我会尽力。

我试图建立一个赤裸的 git 回购(中心)和一个开发网站的工作副本(主要)在一个网络服务器上。我试过模仿 这篇文章。我希望开发工作副本被更新每当中心回购被推到。在我的印象中,这个应用的合适的钩子是 post-update,我是这样创建的:

#!/bin/sh
whoami
cd /path/to/working-copy/
RET=`git pull`
echo $RET

更新

当我从我的本地回购推到裸集线器的变化,我得到以下输出从后更新脚本:

remote: sites
remote: fatal: Not a git repository: '.'

然而,如果我 SSH 进入服务器作为用户’网站’和执行这个脚本手动工程伟大的任何想法,什么可能是错误的钩子或脚本?

23515 次浏览

You probably have a permissions issue. I'm not sure how you have setup your bare git repo, but if it's running under the git user, make sure that git user is allowed to perform the git pull in your project directory.

Optionally try this to find out what user you are when the hook is run:

echo `whoami`

Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR

#!/bin/sh
cd /path/to/working-copy/ || exit
unset GIT_DIR
git pull repo branch


exec git-update-server-info

Try instead:

#!/bin/sh
cd /path/to/working-copy/
env -i git pull

Despite that unset GIT_DIR just works.

the problem occurs when you set GIT_DIR wrongly somewhere else.

you can just add that instead: GIT_DIR=.git/ It will work

In my case I had specified a working tree, and this breaks on some commands, like pull (or more precisely fetch).

To unset the working tree if it is in your git config is via:

git config --unset core.worktree

(There are other ways to set a work tree)

Important to note,

There is next to no change of this being your problem unless you yourself dug this hole around you by using a custom worktree in the first place.

Banter:

This implies to me that git internals use paths relative to the worktree + .git/ in some cases. In my experience worktrees are not well supported whatsoever, except by the most fundamental parts of git. I have not experimented thoroughly, Git would probably behave if I set whatever the git directory config variable is properly, which I have not played with.