如果我们更改 `git config core.hooksPath`,如何恢复为默认值

If we change `git config core.hooksPath`, how to revert back to default

默认情况下,当 运行 在 git 存储库根目录中时,它看起来是空的:

git config core.hooksPath

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

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

如果该选项是在更高级别的配置中设置的(例如,per-user 或 per-system)并且您不想将其从该位置删除,只需为该存储库覆盖它,如果您在 non-bare 存储库中,则可以使用 git config core.hooksPath .git/hooks,如果您在裸存储库中,则可以使用 git config core.hooksPath hooks

来自git-config(1)

The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run.

来自githooks(5)

Before Git invokes a hook, it changes its working directory to either $GIT_DIR in a bare repository or the root of the working tree in a non-bare repository.

因此 non-bare 存储库中的 .git/hooks 和裸存储库中的 hooks 的要求。