Git挂钩:应用`git config core.hooksPath` [英] Git hooks : applying `git config core.hooksPath`

查看:1218
本文介绍了Git挂钩:应用`git config core.hooksPath`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a git repository with a pre-commit hook set up :

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

直到那里,一切正常.当我提交时,钩子正在运行.

Until there, everything works. The hook is running when I commit.

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

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

我现在在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
  • 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 in my-repo outputs ./git-config/hooks

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

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

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

推荐答案

core.hooksPath支持为提交867ad08a2610526edb5723804723d371136fc643 .如果您的Git版本不低于2.9.0,则设置一个hooks-path变量根本无效.

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.

这篇关于Git挂钩:应用`git config core.hooksPath`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆