好的 commit message 让未来的人知道这次变更为什么存在。
它不只是写给现在的 reviewer,也是写给未来排查问题、回滚代码、生成 changelog 的自己和队友。
<type>(<scope>): <subject>
示例:
feat(auth): add GitHub OAuth login
fix(api): handle empty response
docs(git): add troubleshooting guide
refactor(order): simplify pricing calculation
这个格式来自 Conventional Commits,它已经被很多开源项目和自动化发布工具采用。
| type | 含义 |
|---|---|
feat |
新功能 |
fix |
Bug 修复 |
docs |
文档 |
style |
纯格式调整 |
refactor |
不改变行为的重构 |
test |
测试 |
chore |
工具、依赖、维护 |
perf |
性能优化 |
ci |
CI/CD |
好的标题应该:
update、misc、wip 这类无意义表达不推荐:
update
fix bug
misc changes
wip
推荐:
fix(order): reject expired timeout config
docs(ai): add git workflow for coding agents
test(auth): cover expired token case
AI 一次改很多文件时,不要直接提交成一个大 commit。
推荐按意图拆分:
test(order): cover timeout validation
fix(order): reject expired timeout config
docs(order): explain timeout behavior
拆分方式见 AI Commit Splitting。