Skip to content

Instantly share code, notes, and snippets.

@robertpainsi
Last active December 10, 2024 10:35
Show Gist options
  • Save robertpainsi/b632364184e70900af4ab688decf6f53 to your computer and use it in GitHub Desktop.
Save robertpainsi/b632364184e70900af4ab688decf6f53 to your computer and use it in GitHub Desktop.
Commit message guidelines

Commit Message Guidelines

Short (72 chars or less) summary

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 for a commit message

Add CPU arch filter scheduler support

In a mixed environment of…

A properly formed git commit subject line should always be able to complete the following sentence

If applied, this commit will <your subject line here>

Rules for a great git commit message style

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

Information in commit messages

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

Details for each point and good commit message examples can be found on https://wiki.openstack.org/wiki/GitCommitMessages#Information_in_commit_messages

References in commit messages

If the commit refers to an issue, add this information to the commit message header or body. e.g. the GitHub web platform automatically converts issue ids (e.g. #123) to links referring to the related issue. For issues tracker like Jira there are plugins which also converts Jira tickets, e.g. Jirafy.

In header:

[#123] Refer to GitHub issue…
CAT-123 Refer to Jira ticket with project identifier CAT…

In body:

…
Fixes #123, #124

Sources

@CalinZBaenen
Copy link

How do/should I format code in a Git commit message?
Everytime I try using backtick it removes the text (as it's not visible via git log and gone when I do git commit --amend).

Doing git commit --amend is no good, even when I edit the message outside the terminal the text still gets removed for some reason.

Since using backticks won't work, what should I use to format my code?

@CalinZBaenen
Copy link

@Ahmed654321653 What is that, now?

@slnc
Copy link

slnc commented Nov 14, 2022

What is the generally accepted practice if a commit contains numerous unrelated changes that cannot be described succinctly in just 50 characters?

Apply the "Single Responsability Principle" to the commit: split it into smaller logically self-contained commits whose contents can be explained in 50 chars.

I try to stick to that pattern but I sometimes take shortcuts when the cost or splitting is too high or the risk of changing several unrelated things at once is small.

@u-m-i
Copy link

u-m-i commented Aug 25, 2023

Minimalistic approach :

[Action] Short summary (50 chars or less, this is the subject)

(optional) #Issue

More detailed explanatory text, if necessary. Maximun 80 characters to
wrap it.

- Hypen for bullet points.

@kechpaja
Copy link

Use the imperative mood in the subject line

Grammar nitpick: bare infinitive (i.e. "to ", but without the "to"), not imperative. They do look the same, but it's not a command here, it's a description of what will happen when the commit is merged.

@UnitedMarsupials
Copy link

UnitedMarsupials commented Oct 9, 2024

When referencing tickets/issues, I think, the better convention would be to put the references in the body:

Explicitly use Bicycle-class instead of the Vehicle-interface, where applicable

In cases, when bicycle is the only vehicle-type allowed, this simplifies the code
and avoids the redundant casting.

Jira: BOO-11
Bugzilla: 3456

Not only can an organization use multiple ticketing systems in parallel (don't ask), they may also switch from one to another every once in a while.

Putting the tickets into the very summary of the commit does not really help anyone -- the ticket itself is not describing the change...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment