提交后挂钩未运行

发布于 2024-10-19 00:34:19 字数 421 浏览 6 评论 0原文

我的提交后钩子在 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 技术交流群。

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

发布评论

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

评论(4

滿滿的愛 2024-10-26 00:34:19

我将把这个留在这里作为答案,因为我偶然发现了我自己的答案,当我的提交后挂钩没有运行时:

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.

七七 2024-10-26 00:34:19

尝试在 perl 行之前和之后放置一些 echo 行,如下所示:

echo "post-commit started"
perl ...........
echo "post-commit finished"

这样您就可以确认脚本是否确实正在运行,因为当您运行时,

git commit

您应该看到

post-commit started
post-commit finished

输出的末尾。

Try putting some echo lines before and after the perl line like this:

echo "post-commit started"
perl ...........
echo "post-commit finished"

This way you can confirm if the script is actually running, because when you run

git commit

you should see

post-commit started
post-commit finished

Towards the end of your output.

岁吢 2024-10-26 00:34:19

我的提交后脚本没有被调用,因为:

我已将脚本命名为 post-commit.sh,而不仅仅是 post-commit

要启用挂钩脚本,请将文件放入 .git 目录的 hooks 子目录中,该文件具有适当的名称(不带任何扩展名)且可执行。从那时起,就应该调用它。我们将在这里介绍大多数主要的挂钩文件名。 查看 git-scm

不知道为什么我的挂钩的头需要 bash 文件扩展名。

我也没有意识到挂钩脚本不能有文件扩展名。例如,

如果您想使用捆绑的钩子脚本,则必须重命名
他们;他们的文件名都以.sample结尾

希望这对某人有帮助。

My post-commit script wasn't being called because:

I had named the script post-commit.sh, rather than just post-commit.

To enable a hook script, put a file in the hooks subdirectory of your .git directory that is named appropriately (without any extension) and is executable. From that point forward, it should be called. We’ll cover most of the major hook filenames here. See git-scm

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,

If you want to use the bundled hook scripts, you’ll have to rename
them; their file names all end with .sample

Hope this helps someone.

水溶 2024-10-26 00:34:19

除了此处指出的答案之外,请注意,如果您希望在挂钩中输入用户输入,则需要将标准输入重定向到键盘,如下所示(至少对于 bash 脚本而言);

exec < /dev/tty

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);

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