Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git提交钩子-如何使用提交消息钩子检查消息中的字符串?_Git_Perl_Bash_Hook - Fatal编程技术网

Git提交钩子-如何使用提交消息钩子检查消息中的字符串?

Git提交钩子-如何使用提交消息钩子检查消息中的字符串?,git,perl,bash,hook,Git,Perl,Bash,Hook,我需要做一个commit-msg钩子来检查提交消息中是否包含“app.asana”。我搜索了一些参考资料和文档,我知道我需要为此使用commit消息。我必须使用Perl或Bash来实现这一点 有人对此有线索吗?或者我可以找更多的例子来学习如何做 谢谢。我找到了我问题的答案。以防对某人有所帮助 我刚刚在.git/hooks中创建了一个commit msg文件,其中包含 #!/bin/sh test -n "$(grep 'app.asana.com/' ${1})" || { e

我需要做一个commit-msg钩子来检查提交消息中是否包含“app.asana”。我搜索了一些参考资料和文档,我知道我需要为此使用commit消息。我必须使用Perl或Bash来实现这一点

有人对此有线索吗?或者我可以找更多的例子来学习如何做


谢谢。

我找到了我问题的答案。以防对某人有所帮助

我刚刚在
.git/hooks
中创建了一个
commit msg
文件,其中包含

#!/bin/sh

test -n "$(grep 'app.asana.com/' ${1})" || {
        echo >&2 "ERROR: Commit message is missing Asana's task link.\n\nPlease append the Asana's task link relative to this commit into the commit message."
        exit 1
}
每个用户都需要在
.git/hooks
中有一个
commit msg
文件。然后,作为一种解决方案,我使用另一个名为
commit msg hook.sh
的文件将
commit msg
添加到项目文件夹中(这样我就可以拉取它),该文件包含:

#!/bin/sh

cp commit-msg .git/hooks/commit-msg
chmod +x .git/hooks/commit-msg
echo "\nThe commit-msg hook was added to git hooks"

我欢迎任何改进我所做工作的建议。谢谢。

可能会有帮助。我已经浏览了此页面,但谢谢。经过更多的研究,我做到了。。。其实很简单,是我一个人,还是第一段代码中的第二行不需要/不起作用
chmoda+x.git/hooks/commit-msg
是使commit-msg可执行,以便与git一起运行。但是,如果文件没有
+x
,则该文件(以及该命令)将永远无法执行,因此在实际文件中包含该命令是没有意义的。这篇文章是2013年的,所以如果我错了,请大家纠正我。肯定有人注意到了吗?@Russell你说得对。我把它修好了,它正在接受同行评审。