简体   繁体   English

Git 预提交挂钩“无错误”错误消息

[英]Git pre-commit hook “No error” error message

I have a pre-commit hook that when I run returns this error:我有一个预提交挂钩,当我运行时会返回此错误:

error: cannot spawn.git/hooks/pre-commit: No error

I have a #!/bin/sh at the top and have definitely used chmod +x on it.我在顶部有一个#!/bin/sh并且肯定使用了chmod +x However, those appear to be fixes for when there is a no such file or directory error.但是,当没有此类文件或目录错误时,这些似乎是修复。 My error simply says No error and I cannot work out why.我的错误只是说No error ,我不知道为什么。

Code in the hook:钩子里的代码:

#!/bin/sh

changes() {
  git diff --name-only --diff-filter=AMDR --cached @~..@
}

if changes | grep -q dirname {
  echo "Test"
}

Check first, as in here , if your script does have a final newline.首先检查你的脚本是否有最后的换行符,就像在这里一样。
Its absence would trigger a "no error" message.它的缺失将触发“无错误”消息。

Check also the eol style (end of line): LF is prefered for those bash script.还要检查 eol 样式(行尾):对于那些 bash 脚本,首选 LF。

The OP compsciman confirms in the comments that switching to Git For Windows 2.26 from 2.21 solved the issue. OP compsciman 在评论中确认从 2.21 切换到 Git For Windows 2.26 解决了这个问题。

The only recent modification to pre-commit involves the removal of git config --bool option ( commit 81e3db4 ) that I mentioned in " How to color the Git console? ".最近对pre-commit的唯一修改涉及删除我在“如何为 Git 控制台着色? ”中提到的git config --bool选项( commit 81e3db4 )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM