如果我们更改了 `git config core.hooksPath`,怎样恢复默认设置?

22

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

git config core.hooksPath

如果我们将git config core.hooksPath更改为git config core.hooksPath myhooks,那么我的问题是:我们如何将其改回默认设置?我们应该取消设置(如何?),还是应该将其设置为.git/hooks,就像在git config core.hooksPath .git/hooks中一样?


3
你尝试过使用 git config --unset core.hooksPath 命令吗? - larsks
肯定 unset 可能会起作用,如果它没有设置,那么 Git 将默认使用 .git/hooks。 - Alexander Mills
1
你也可以在 ~/.gitconfig 文件中 [core] 部分下删除自定义的设置。 - zyy
1个回答

31
答案取决于设置的位置以及您想要更改的内容。 如果在本地存储库中设置了选项并且您想要撤消它,则git config --unset core.hooksPath足以取消设置,这将使Git选择默认选项。
如果该选项在更高级别的配置中设置(例如每个用户或每个系统),并且您不想将其从该位置中删除,而只是要覆盖此存储库的选项,则可以使用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.

因此,在非裸存储库中需要.git/hooks,而在裸存储库中需要hooks

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接