我有一个设置了 pre-commit hook 的 git 代码仓库:
my-repo
|- .git
|- hooks
|- pre-commit # I made this file executable
到那时,一切都正常。我提交时挂钩程序运行。
=================================
现在我在my-repo
中运行git config core.hooksPath ./git-config/hooks
。
文件夹结构如下:
my-repo
|- .git
|- hooks
|- git-config
|- hooks
|- pre-commit # I made this file executable as well
发生的情况是:
- 新的预提交脚本不会在提交时运行
- 如果我将旧的预提交脚本留在
my-repo/.git/hooks
中,则旧的预提交脚本仍然在提交时运行 - 在
my-repo
中运行git config --get core.hooksPath
会输出./git-config/hooks
如何使新的预提交钩子在提交时运行?
这里是我显然没有很好理解的文档链接:
https://git-scm.com/docs/git-config
https://git-scm.com/docs/githooks
core.hooksPath
。默认的钩子是否会与您的自定义钩子一起运行,还是只会运行您的自定义钩子? - Xerricore.hooksPath
选项会覆盖默认值(./.git/hooks
),因此只有在你指定的新文件夹中的钩子脚本才会被检测和运行。 - Nicolas Marshall