Git hooks 是 Git 自动在工作流程中的某些特定点(提交前/后、推送、合并等)运行的脚本。它们启用自动化 — 强制执行标准、运行检查和触发操作 — 并广泛用于代码质量和 CI 集成。
Hooks 是什么
Hooks are executable scripts in .git/hooks/ (or managed by tools) that Git runs on EVENTS:
CLIENT-SIDE (local):
pre-commit → before a commit is created (lint, format, run quick tests)
commit-msg → validate/format the commit message
pre-push → before pushing (run tests, prevent pushing broken code)
post-merge/checkout → after merge/checkout (e.g. reinstall dependencies)
SERVER-SIDE (on the remote):
pre-receive / update → enforce policies on push (reject bad pushes)
post-receive → trigger deployment/CI/notifications after a push
