TIPS
Git
版本控制
技巧
版本控制:commit message怎么写才不是"update"?
平
平台管理员2026年2月21日
15 次阅读
"update"是一种懒惰
我翻过自己三个月前的 commit 记录,连续十几个都是 "update"。我想找某个参数改动是哪天做的,只能逐个 diff。那次我花了四十分钟。
在 DeepCode 里做代码项目时,commit message 是未来的你给现在的你写的求救信。
四个技巧
- 用祈使句开头。"Add"、"Fix"、"Refactor"、"Update"可以,但后面必须跟具体内容。例如:"Fix LJ cutoff bug in energy calculation"。
- 标题控制在50字以内。超过就拆成正文。GitHub 等平台的显示宽度有限。
- 说明"为什么",不是"做了什么"。代码已经告诉读者做了什么,commit message 要解释动机。
- 关联 issue 或任务。"Closes #23" 或 "See project note 2024-05"。
我的模板
Fix: correct lattice parameter relaxation threshold
Previous threshold (0.01 Å) caused false convergence for
soft structures. New threshold (0.005 Å) matches paper X.
Relates to #12
什么时候可以写"update"
几乎不可以。如果真不知道写什么,说明这次 commit 包含了太多不相关改动。拆开再提交。