提交后挂钩未运行
我的提交后钩子在 git 之后没有运行。我已经验证,如果我只是从终端运行该钩子,它确实可以工作。挂钩中的代码是:
#!/bin/sh
#.git/hooks/post-commit
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".
perl -pi -e 's/([a-f0-9]+)$/'$( git rev-parse HEAD )/ ../../config/commit.git
我确实将文件重命名为 ./.git/hooks/ 中的提交后,权限为 -rwxr-xrx
所以我不确定为什么它不起作用。
My post commit hook is not running after git. I have verified that the hook does work if I just run it from the terminal. The code in the hook is:
#!/bin/sh
#.git/hooks/post-commit
# An example hook script that is called after a successful
# commit is made.
#
# To enable this hook, rename this file to "post-commit".
perl -pi -e 's/([a-f0-9]+)$/'$( git rev-parse HEAD )/ ../../config/commit.git
I did rename the file to post-commit in ./.git/hooks/ and the permissions are -rwxr-x-r-x
so I am not sure why it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我将把这个留在这里作为答案,因为我偶然发现了我自己的答案,当我的提交后挂钩没有运行时:
chmod +x .git/hooks/post-commit< /code>
可能适用于任何类型的钩子。
事实上,可能适用于任何类型的脚本。
I'll leave this here as an answer because I stumbled upon my own answer for when my post-commit hook wasn't running:
chmod +x .git/hooks/post-commit
Probably applies to any kind of hook.
In fact, probably applies to any kind of script.
尝试在 perl 行之前和之后放置一些 echo 行,如下所示:
这样您就可以确认脚本是否确实正在运行,因为当您运行时,
您应该看到
输出的末尾。
Try putting some echo lines before and after the perl line like this:
This way you can confirm if the script is actually running, because when you run
you should see
Towards the end of your output.
我的提交后脚本没有被调用,因为:
我已将脚本命名为
post-commit.sh
,而不仅仅是post-commit
。不知道为什么我的挂钩的头需要 bash 文件扩展名。
我也没有意识到挂钩脚本不能有文件扩展名。例如,
希望这对某人有帮助。
My post-commit script wasn't being called because:
I had named the script
post-commit.sh
, rather than justpost-commit
.Not sure why I had in my head that hooks needed the bash file extension.
I also didn't realize hook scripts cannot have file extensions. For example,
Hope this helps someone.
除了此处指出的答案之外,请注意,如果您希望在挂钩中输入用户输入,则需要将标准输入重定向到键盘,如下所示(至少对于 bash 脚本而言);
In addition to the answers noted here, note that if you are expecting user input in your hook, you need to redirect standard input to the keyboard like so (at least for a bash script);