如何正确使用post-receive hook?

发布于 2024-10-04 22:54:16 字数 251 浏览 4 评论 0原文

我的目录结构是:

~/parent.git/.git/hooks/post-receive

post-receive 挂钩如下所示:

#!/bin/sh
git checkout -f

当我推入parent.git 时,脚本不会运行。我无法弄清楚这个问题,因为互联网上的每一个部分都说这应该有效。

我在接收后进行了 chmod,所以我知道这不是问题。非常感谢任何帮助。

My directory structure is:

~/parent.git/.git/hooks/post-receive

The post-receive hook looks like:

#!/bin/sh
git checkout -f

When I push into parent.git, the script does not run. I can't figure out the problem, as every bit of the internet says this should work.

I chmod'd post-receive, so I know that is not the problem. Any help is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

楠木可依 2024-10-11 22:54:16

正如克里斯提到的,你似乎有同样的问题 reset Hard on git Push

特别是钩子运行时将 CWDGIT_DIR 设置为 .git 目录。这会导致 checkout 命令在 .git 目录中运行,并且有关该命令的正常错误被覆盖。

如果您在远程 .git 目录中执行 ls 操作,您应该在那里找到完整的签出。

最简单的方法是在 checkout 命令前面指定 GIT_WORK_TREE:

GIT_WORK_TREE=/my/git/checkout git checkout -f

Chris 链接的脚本 ( http://utsl.gen.nz/git/post-update)应该可以解决这个问题和其他一些潜在问题。

As Chris mentioned you seem to have the same problem as reset hard on git push

Specifically hooks run with CWD and GIT_DIR set to the .git directory. This results in the checkout command running in the .git dir and the normal error about that being overridden.

If you do an ls in the remote .git dir you should find a full checkout in there.

The easiest way around this is to specify GIT_WORK_TREE on the front of the checkout command:

GIT_WORK_TREE=/my/git/checkout git checkout -f

The script Chris linked (http://utsl.gen.nz/git/post-update) is supposed to take care of this and a few other potential issues.

稳稳的幸福 2024-10-11 22:54:16

如果我有一个猜测,我会说推送用户没有权限在该目录中执行签出。我建议您做的是构建最小的工作脚本并从那里构建。 IE,而不是:

git checkout -f

执行:

echo "Got here" > /tmp/git_push_log

然后尝试:

echo "Got here" > pwd_test

检查您对正在运行的目录以及需要哪些权限的假设。

If I had a guess, I'd say that the pushing user doesn't have permission to perform the checkout in that directory. What I'd suggest you do is to build the minimal working script and build from there. IE, instead of:

git checkout -f

Do:

echo "Got here" > /tmp/git_push_log

Then try:

echo "Got here" > pwd_test

To check your assumptions about what directory this is operating in and what permissions are required.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文