【发布时间】:2017-01-12 22:21:24
【问题描述】:
我有一个设置了预提交挂钩的 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。除了您的自定义挂钩之外,还会运行默认的适合挂钩还是只运行您的自定义挂钩? -
@Xerri
core.hooksPath选项会覆盖默认值 (./.git/hooks),因此只会检测并运行您指定的新文件夹中的挂钩脚本。