快速的 Git hooks 管理器
lefthook 用 lefthook.yml 管理 pre-commit、pre-push 等钩子,支持并行执行和只检查变更文件。它是单二进制,适合多语言仓库。
lefthook install
lefthook run pre-commit
lefthook run pre-commit --all-files
lefthook run pre-push
lefthook add pre-commit
lefthook uninstall
lefthook version
lefthook.yml:
pre-commit:
parallel: true
commands:
lint:
glob: "*.{js,ts}"
run: npm run lint -- {staged_files}
format:
glob: "*.{js,ts}"
run: npx prettier --write {staged_files}
stage_fixed: true
pre-push:
commands:
test:
run: npm test
lefthook install 会写入 .git/hooks;和 husky/pre-commit 同时使用会互相覆盖。{staged_files} 只包含暂存文件;全量检查用 --all-files 或 {all_files}。stage_fixed: true 才会把自动修复后的文件重新加入暂存区。glob 语法和 shell glob 不完全相同;匹配不到文件时命令可能直接跳过。parallel: false 或用 piped。LEFTHOOK=0 可以临时跳过;不要把跳过当成常规流程。pre-commit — Python 生态常用 hooks 框架commitlint — 提交信息检查git — 提交操作