I Built a Git Hook That Makes Revert Commits Conventional
说明与用途
创建了一个 Git 钩子,将回滚提交消息转换为 Conventional Commits 格式,保持提交历史一致性。
问题
Git’s default revert message does not conform to Conventional Commits format, causing inconsistencies in commit history.
结果
Revert commits now match Conventional Commit syntax, improving consistency and tooling compatibility.
工作流
- Create a Git hook using prepare-commit-msg
- Configure the hook to rewrite revert messages
- Install globally or per repository
- Set desired style via git config revert-hook.style
- Run git revert and observe the rewritten message
证据
The hook uses Git's prepare-commit-msg hook. It runs after Git prepares a revert message and before the editor opens.
The project has no test framework dependency. test.sh creates temporary Git repositories and exercises installation, overwrite protection, message rewriting, styles, fallback behavior, global installation, and cleanup.
- 记录日期: 2026-09-15T23:01:13.878Z