bash 提交后挂钩未运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5084100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Post Commit Hook Not Running
提问by Dave Long
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:
我的提交后钩子没有在 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
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.
我确实将文件重命名为 ./.git/hooks/ 中的 post-commit 并且权限是-rwxr-x-r-x
这样我不确定为什么它不起作用。
采纳答案by Peter Farmer
Try putting some echo lines before and after the perl line like this:
尝试在 perl 行前后放置一些 echo 行,如下所示:
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.
在你的输出结束时。
回答by Steven Lu
I'll leave this here as an answer because I stumbled upon my own answer for when mypost-commit hook wasn't running:
我将把它留在这里作为答案,因为当我的post-commit 钩子没有运行时,我偶然发现了自己的答案:
chmod +x .git/hooks/post-commit
chmod +x .git/hooks/post-commit
Probably applies to any kind of hook. In fact, probably applies to any kind of script.
可能适用于任何类型的钩子。事实上,可能适用于任何一种脚本。
回答by Bryce Johnson
My post-commit script wasn't being called because:
我的提交后脚本没有被调用,因为:
I had named the script post-commit.sh
, rather than just post-commit
.
我已经命名了脚本post-commit.sh
,而不仅仅是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
要启用钩子脚本,请将文件放在 .git 目录的 hooks 子目录中,该文件名称适当(不带任何扩展名)且可执行。从那时起,它应该被调用。我们将在这里介绍大部分主要的钩子文件名。见 git-scm
Not sure why I had in my head that hooks needed the bash file extension.
不知道为什么我脑子里认为钩子需要 bash 文件扩展名。
I also didn't realize hook scripts cannothave 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
如果你想使用捆绑的钩子脚本,你必须重命名它们;他们的文件名都以 .sample 结尾
Hope this helps someone.
希望这可以帮助某人。
回答by n00b
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);
除了这里提到的答案之外,请注意,如果您希望在钩子中输入用户输入,则需要像这样将标准输入重定向到键盘(至少对于 bash 脚本);
exec < /dev/tty