| 钩子位置 | .git/hooks/commit-msg,或 core.hooksPath 指定目录 |
|---|---|
| 传入参数 | 保存提交信息的临时文件路径 |
| 执行时机 | git commit 生成信息之后、提交完成之前 |
钩子示例(提交校验)
钩子示例(提交校验)
#!/bin/sh
npx --no-install commitlint --edit "$1"
统一钩子目录
统一钩子目录
git config core.hooksPath .githooks
chmod +x .githooks/commit-msg钩子不随 clone 分发,需要每台机器安装或由工具框架统一管理;文件必须可执行,否则静默不生效。