如何正确使用post-receive hook?
我的目录结构是:
~/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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如克里斯提到的,你似乎有同样的问题 reset Hard on git Push
特别是钩子运行时将
CWD
和GIT_DIR
设置为.git
目录。这会导致 checkout 命令在 .git 目录中运行,并且有关该命令的正常错误被覆盖。如果您在远程
.git
目录中执行 ls 操作,您应该在那里找到完整的签出。最简单的方法是在 checkout 命令前面指定 GIT_WORK_TREE:
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
andGIT_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:
The script Chris linked (http://utsl.gen.nz/git/post-update) is supposed to take care of this and a few other potential issues.
如果我有一个猜测,我会说推送用户没有权限在该目录中执行签出。我建议您做的是构建最小的工作脚本并从那里构建。 IE,而不是:
执行:
然后尝试:
检查您对正在运行的目录以及需要哪些权限的假设。
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:
Do:
Then try:
To check your assumptions about what directory this is operating in and what permissions are required.