用 core.hooksPath 共享 Git 钩子
把钩子放进仓库并让全团队使用。
运行 git config core.hooksPath .githooks,从受版本控制的目录加载钩子。
01命令
命令
$ git config core.hooksPath .githooks02作用说明
钩子可在提交前做 lint、格式化或测试,但 .git/hooks 不受版本控制。把 .githooks 目录纳入仓库并设置 core.hooksPath,即可自动共享检查,把人工习惯变成强制自动化。
03风险
!注意: 钩子会执行任意代码;提交钩子脚本变更前请先审查。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- git-githooks documentation依据: Documents client-side hooks including pre-commit and core.hooksPath.
最后验证: 2026-10-13 · 分类: 开发者