Commit subject 和 Decsription的区别

发布时间 2023-09-05 10:05:27作者: 小张的开发笔记

在github上,每个 commit 都有一个 subjectdescription 字段。

Commit Subject
这通常是一句简短的摘要,它说明了这个 commit 的主要目的。
例如:"Add new feature" 或者 "Fix bug"。

在Git中,由于提交消息(subject)的主要目的是让其他人了解自己所做的修改,所以清晰和明了是非常重要的。在你编写提交消息时,简洁明了的描述修改内容,例如:“修复拼写错误”、“添加新功能”、 “更新文档”等。

Commit Description
这是对 commit 更详细的描述。它可以包含为什么做这些改变,解决了什么问题,以及有什么副作用等等。在这里,可以详述修改内容,对修改背后的原因,用以解决什么问题等等进行详细描述。

例如:

commit subject: Fix issue #123

commit description: 

The issue #123 was caused by null pointer exception due to missing data 
checks. This commit fixes that issue by adding the necessary null checks 
and therefore resolves the null pointer exception. It's also important to 
note that this fix does not have any known side effects on the system.

上面例子中,Fix issue #123 是commit subject,紧接着的部分是commit description。

值得注意的是,科学并合理的commit subject和description,一方面方便自己后期查找问题,另一方面也方便他人更好的理解你的修改。