什么可能导致我的 git 提交前和提交后挂钩无法运行?
(请注意:这个问题不是重复的;其他每个问题的答案要么是chmod +x“没有文件扩展名”,要么这里的问题都不是)
它们是可执行的:
$ ls -alh .git/hooks/*-commit
-rwxr-xr-x … .git/hooks/post-commit
-rwxr-xr-x … .git/hooks/pre-commit
这是他们每个人的内容:
#!/bin/sh
echo "$0 IS RUNNING"
exit 1
手动运行它们:
$ .git/hooks/pre-commit
.git/hooks/pre-commit IS RUNNING
但它们不会git在提交时运行:
$ git commit -am "Test hooks"
[master d17c0f38] Test hooks
1 file changed, 1 insertion(+)
这是 git 2.16.2
Von*_*onC 22
例如,我已经看到配置core.hooksPath被设置为另一个路径而不是$GIT_DIR/hooks,从而忽略该文件夹中的挂钩。
检查您的git config core.hooksPath输出,更一般地 检查 git config -l任何不寻常的设置。
请注意, agit commit -n会跳过 pre-commit hook。
wolever编辑:
我已将此添加到我core.hooksPath目录中的脚本中,如果它们存在,它将运行 repo 的钩子:
#!/bin/sh
set -eu
hook_name="$(basename "$0")"
hook_script=".git/hooks/$hook_name"
[ -e "$hook_script" ] && "$hook_script"
exit 0
Run Code Online (Sandbox Code Playgroud)
Ale*_*der 18
就我而言,core.hooksPath设置projRootDir/.git/config不正确。从配置文件中删除条目就成功了
Mus*_*NGA 10
在项目(存储库)根目录中执行此命令应该可以修复问题
git config --local core.hooksPath .git/hooks
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9633 次 |
| 最近记录: |