【问题标题】:If we change `git config core.hooksPath`, how to revert back to default如果我们更改 `git config core.hooksPath`,如何恢复为默认值
【发布时间】:2019-09-27 20:16:45
【问题描述】:

默认情况下,在 git repo root 中运行时,它看起来是空的:

git config core.hooksPath

如果我们将 git config core.hooksPath 更改为 git config core.hooksPath myhooks,我的问题是 - 我们如何将其更改回默认值?我们应该取消设置值(如何?),还是应该将其设置为.git/hooks,如git config core.hooksPath .git/hooks

【问题讨论】:

  • 你试过git config --unset core.hooksPath吗?
  • 确定未设置可能会起作用,如果未设置,则 git 将默认为 .git/hooks
  • 您也可以在~/.gitconfig中删除[core]下的自定义设置。

标签: git githooks git-config


【解决方案1】:

答案取决于设置的位置以及您想要更改的内容。如果您在本地存储库中设置了该选项并且您想撤消它,那么git config --unset core.hooksPath 足以取消设置它,这将使 Git 选择默认选项。

如果该选项在更高级别的配置中设置(例如,每个用户或每个系统)并且您不想从该位置删除它,只为该存储库覆盖它,您可以使用git config core.hooksPath .git/hooks如果您在非裸存储库中,或者git config core.hooksPath hooks 如果您在裸存储库中。

来自git-config(1)

路径可以是绝对的或相对的。相对路径被视为相对于运行钩子的目录。

来自githooks(5)

在 Git 调用钩子之前,它会将其工作目录更改为裸存储库中的 $GIT_DIR 或非裸存储库中工作树的根目录。

因此要求.git/hooks 在非裸存储库中,hooks 在裸存储库中。

【讨论】:

    猜你喜欢
    • 2017-11-12
    • 2017-01-12
    • 1970-01-01
    • 1970-01-01
    • 2013-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    相关资源
    最近更新 更多