如何正确使用接收后挂钩? [英] How to properly use post-receive hook?
问题描述
我的目录结构是:
〜/parent.git/.git/hooks/post-receive
~/parent.git/.git/hooks/post-receive
接收后挂钩看起来像:
#!/bin/sh
git checkout -f
当我推送到parent.git时,脚本无法运行.我无法找出问题所在,因为互联网的每一个角落都说这应该可行.
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.
推荐答案
As Chris mentioned you seem to have the same problem as reset hard on git push
尤其是将CWD
和GIT_DIR
设置为.git
目录的钩子.这导致checkout命令在.git
目录中运行,并且有关该命令的常规错误被覆盖.
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.
如果在远程.git
目录中执行ls命令,则应该在其中找到完整的签出地址.
If you do an ls in the remote .git
dir you should find a full checkout in there.
最简单的方法是在checkout命令的前面指定GIT_WORK_TREE:
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
克里斯(Chris)链接的脚本( http://utsl.gen.nz/git/post-更新)应该可以解决此问题以及其他一些潜在问题.
The script Chris linked (http://utsl.gen.nz/git/post-update) is supposed to take care of this and a few other potential issues.
这篇关于如何正确使用接收后挂钩?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!