Creating Good Commit Messages

Jan 24, 2022

分享这篇文章:

Having a well-crafted commit message will save you from using many tools to inspect changes in a project. Proper commit messages will make it easy to understand why a change was made at a particular time. This post explains the approach we recommend using in commit messages.

Format of the Commit Message

The format of a commit message can be separated in three distinct parts separated by a blank line: the message summary, body, and footer. The summary is required but the other two sections are optional. When a change is very simple, a message summary is usually enough.

Message Summary
<blank line>
Message Body
<blank line>
Message Footer

Message Summary

  • Give a summary of your change in around 50 characters or less
  • Use the imperative mood in the subject line
# Bad
❯ I added a README.md to the project
# Good
❯ Add README.md to the project
  • No dot at the end
  • Capitalize first letter

Message Body

  • Wrap the body at around 72 characters. You have to do it manually (or configure your editor to do it for you) because Git doesn't do it for you. If you don't then your paragraphs will flow off the edge of the screen when using something like `git log`.
  • Leave out the details about how a change was made. When a commit is explained, focus on the why and what. Details about how a change was made can be explored simply by taking a look at the code. If the code being committed necessitates extra explanation, then this is best handled with source comments.
  • Bullet points and new lines are okay to use.

Message Footer

  • Mention breaking changes if applicable
  • Add a reference to the issue or other issues if applicable

Sample of a Good Commit Message

Restore Freshchat on a few pages
Freshchat was recently removed in f47ecb0.
The community team requested that we restore it on 3 pages:
- /premium-domains-nft-sale
- /cart
- /checkout
[#179377974]

Recommended Readings

Author

Hassan Ali

当前空缺职位

  • Data Engineer, Analytics - Remote

    全职 · Remote, US/Canada

  • Director of Engineering, Mobile - Remote

    全职 · Remote, US/Canada

  • Director of Platform Engineering - Remote

    全职 · Remote, US/Canada

  • General Opportunities - Engineering

    全职 · Remote, Global

  • Senior Android Developer

    全职 · Remote, US/Canada

  • Senior Android Developer

    全职 · Remote, Europe

  • Senior Blockchain Developer - Remote

    全职 · Remote, Europe

  • Senior Fullstack Engineer, Ecommerce - Remote

    全职 · Remote, US/Canada

  • Senior Fullstack Engineer, Login - Remote

    全职 · Remote, US/Canada

  • Site Reliability Engineer - Remote

    全职 · Remote, US/Canada

在社交媒体上关注我们

帮助中心