📜  如何在 GitHub 中编写好的提交消息?(1)

📅  最后修改于: 2023-12-03 15:38:15.990000             🧑  作者: Mango

如何在 GitHub 中编写好的提交消息?

编写好的提交消息不仅会让其他开发者更容易理解你的代码更改,还可以提高团队协作效率。以下是在 GitHub 中编写好的提交消息的一些技巧:

1. 提供简明扼要的摘要

提交消息的第一行应当提供一句简明扼要的摘要,总结所做更改的主要内容。建议不要超过50个字符。如下所示:

feat: add support for custom fonts

其中,“feat”是类型,表示对功能的添加。

2. 提供更详细的描述

第一行摘要后面,应当提供更详细的描述。下面的例子解释了更改的原因、所考虑的其他选择以及实现过程中的一些重要决策:

feat: add support for custom fonts

Previously, this application was only able to render fonts that were included in the CSS file. This change allows users to specify a URL to a font file, which they can host on any server they like.

We considered using Google Fonts API, but rejected it for two reasons. Firstly, it requires users to be online in order to use the application. Secondly, it adds unnecessary complexity to the application by relying on a third-party API.

To implement this feature, we refactored the existing CSS parser to support @font-face rules. We also introduced a new FontLoader class to asynchronously load the font files.
3. 使用合适的动词和语态

提交消息应当使用命令式语态,使用行为动词开头,例如“add”、“fix”、“remove”、“update”等。同时,应当使用正确的语态,清晰地传达更改是由哪个人或哪个工具生成的。下面是一些例子:

  • Use the imperative mood in your subject line: "Add", not "Added" or "Adds!"
  • Use the active voice in the subject line and body: "Fix bug" and not "Bug fixed"
  • Use the past tense in the body of the message: "Fixed bug" rather than "Fix bug"
4. 使用适当的标签

在 GitHub 中,提交消息还可以使用标签(Labels)来帮助组织更改,并使其更易于搜索和过滤。建议使用常见的标签,如bug、feature、documentation、refactor等。如下所示:

feat: add support for custom fonts
bug: fix issue with submenus not appearing
refactor: extract common logic into helper function
参考资料