如何正确使用接收后挂钩? [英] How to properly use post-receive hook?

查看:80
本文介绍了如何正确使用接收后挂钩?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目录结构是:

〜/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

尤其是将CWDGIT_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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆