Git钩子:应用`git config core.hooksPath`
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39332407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git hooks : applying `git config core.hooksPath`
提问by Nicolas Marshall
I have a git repository with a pre-commit hook set up :
我有一个带有预提交挂钩的 git 存储库:
my-repo
|- .git
|- hooks
|- pre-commit # I made this file executable
Until there, everything works. The hook is running when I commit.
直到那里,一切正常。当我提交时钩子正在运行。
=================================
==================================
I now run git config core.hooksPath ./git-config/hooks
in my-repo
.
我现在跑git config core.hooksPath ./git-config/hooks
了my-repo
。
The folder structure is this one :
文件夹结构是这样的:
my-repo
|- .git
|- hooks
|- git-config
|- hooks
|- pre-commit # I made this file executable as well
What happens is :
发生的事情是:
- the new pre-commit script doesn't run on commit
- the old pre-commit script still runs on commit if I leave it in
my-repo/.git/hooks
- running
git config --get core.hooksPath
inmy-repo
outputs./git-config/hooks
- 新的预提交脚本不会在提交时运行
- 如果我将其保留,则旧的预提交脚本仍会在提交时运行
my-repo/.git/hooks
git config --get core.hooksPath
在my-repo
输出中运行./git-config/hooks
How can I make the new pre-commit hook run on commit ?
如何让新的预提交钩子在提交时运行?
Here's the link to the docs I apparently don't understand well :
https://git-scm.com/docs/git-config
https://git-scm.com/docs/githooks
这是我显然不太了解的文档的链接:
https: //git-scm.com/docs/git-config
https://git-scm.com/docs/githooks
回答by torek
The core.hooksPath
support is new in Git version 2.9, having been put in with commit 867ad08a2610526edb5723804723d371136fc643
. If your Git version is not at least 2.9.0, setting a hooks-path variable will have no effect at all.
该core.hooksPath
支持是Git 版本 2.9 中的新支持,已与commit867ad08a2610526edb5723804723d371136fc643
一起提供。如果您的 Git 版本不是至少 2.9.0,则设置 hooks-path 变量将根本不起作用。