我有一个预提交的挂钩,当我运行时会返回以下错误:
error: cannot spawn .git/hooks/pre-commit: No error
我的顶部有一个#!/bin/sh
,并且肯定使用了chmod +x
。但是,这些似乎是针对没有此类文件或目录错误的修复程序。我的错误只是说No error
,我无法弄清原因。
挂钩中的代码:
#!/bin/sh
changes() {
git diff --name-only --diff-filter=AMDR --cached @~..@
}
if changes | grep -q dirname {
echo "Test"
}
答案 0 :(得分:1)
请先检查as in here(如果您的脚本中有最后一个换行符)。
如果不存在,则会触发“无错误”消息。
还要检查eol样式(行尾):那些bash脚本更喜欢LF。
OP compsciman确认in the comments,从2.21切换到Windows 2.26的Git解决了该问题。
最近对pre-commit
进行的唯一修改涉及删除了我在“ commit 81e3db4”中提到的git config --bool
选项(How to color the Git console?)。