Writing git commit messages that everybody understands — especially your team

Yuil Tripathee
2 min readAug 24, 2019

Basic guidelines, rules, information to display, do’s and don’ts, necessity

Basic guidelines

The length of summary should be short as 72 characters with hard limit of 80.

More detailed explanatory text. Wrap it to 72 characters. The blank
line separating the summary from the body is critical (unless you omit
the body entirely).

Write your commit message in the imperative: “Fix bug” and not “Fixed
bug” or “Fixes bug.” This convention matches up with commit messages
generated by commands like git merge and git revert.

Further paragraphs come after blank lines.

  • Bullet points are okay, too.
  • Typically a hyphen or asterisk is used for the bullet, followed by a
    single space. Use a hanging indent.

Example

ADD CPU arch filter scheduler supportIn a mixed environment of…
Sample git commit messages from a open source project on GitHub

The rules — not “rules”, but better to follow:

  • Separate subject from body with blank line
  • Do not end subject line with period
  • Capitalize subject line with a period
  • Use imperative mood in subject line
  • Wrap lines at 72 characters
  • Use the body to explain what and why you have done something. In most cases, you have to leave out details about how a changes has been made.

The information to include in git messages

  • Describe why a change being made
  • How does it address the issue?
  • What effect does the patch have?
  • Do not assume the reviewer understand what the original problem was
  • Do not assume the code is self evident/self documenting
  • Read the commit message to see if the hints at improved code structure
  • The first commit line is the most important
  • Describe any limitation of the current code
  • Do not include patch set specific comments

Do’s and don’ts:

Do’s:

  • Always use imperatives at the subject
  • Always leave second line blank
  • Line break the commit message

Not to do’s:

  • Don’t end the summary line with a period — it’s a title and title doesn’t end with a period

The necessity

While working with the teams, good commit helps other members in a team to easily understand about the changes made by the commit despite of language centric barriers and variations of the methods of understanding the system individually.

Furthermore, even for yourself, proper git commit messages helps yourself to review the changes you made easily even after the long time you have returned into the project.

Sources:

  1. Google
  2. Quora
  3. Others…

--

--