Git hooks:应用`git config core.hooksPath`

问题描述 投票:0回答:2

我有一个 git 存储库,设置了预提交挂钩:

my-repo
|- .git
   |- hooks
      |- pre-commit     # I made this file executable

在那之前,一切正常。当我提交时,钩子正在运行。

====================================

我现在在

git config core.hooksPath ./git-config/hooks
运行
my-repo

文件夹结构是这样的:

my-repo
|- .git
   |- hooks
|- git-config
   |- hooks
      |- pre-commit     # I made this file executable as well

发生的事情是:

  • 新的预提交脚本不会在提交时运行
  • 如果我将旧的预提交脚本保留在
    my-repo/.git/hooks
  • 中,它仍然会在提交时运行
  • git config --get core.hooksPath
    中运行
    my-repo
    输出
    ./git-config/hooks

如何使新的预提交挂钩在提交时运行?

这是我显然不太理解的文档的链接:
https://git-scm.com/docs/git-config
https://git-scm.com/docs/githooks

git githooks
2个回答
45
投票

core.hooksPath
支持是 Git 版本 2.9 中的新增功能,已与 commit
867ad08a2610526edb5723804723d371136fc643
一起添加。如果你的 Git 版本不是 2.9.0 以上,设置 hooks-path 变量根本没有效果。


0
投票

除了 git config 之外,我还需要将

chmod +x
添加到预提交文件中。

git config --local core.hooksPath .githooks/

chmod +x .githooks/pre-commit

© www.soinside.com 2019 - 2024. All rights reserved.