Commit Messages
Write a good commit message
Commit messages are one of the most common ways developers communicate with each other, so it’s important to clearly communicates any changes.
Typically, the audience of a commit message is:
- People reading the commit timeline.
- People debugging code
The Anatomy of a Commit Message
Basic:
git commit -m <message>
Detailed:
git commit -m <title> -m <description>
5 Steps to Write Better Commit Messages
Let's summarize the suggested guidelines:
- Capitalization and Punctuation: Capitalize the first word and do not end in punctuation. If using Conventional Commits, remember to use all lowercase.
- Mood: Use imperative mood in the subject line.
Example– Add fix for dark mode toggle state
. Imperative mood gives the tone of an order or request. - Type of Commit: Specify the type of commit. It is recommended and can be even more beneficial to have a consistent set of words to describe your changes.
Example: Bugfix, Update, Refactor, Bump, and so on. See the section on Conventional Commits below for additional information. - Length: The first line should ideally be no longer than 50 characters, and the body should be restricted to 72 characters.
- Content: Be direct, try to eliminate filler words and phrases in these sentences (examples: though, maybe, I think, kind of). Think like a journalist.
Why use a commit message convention?
A well-organized commit message history leads to more readable messages that are easy to follow when looking through the project history.
The commit type can include the following:
feat
– a new feature is introduced with the changesfix
– a bug fix has occurredchore
– changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)refactor
– refactored code that neither fixes a bug nor adds a featuredocs
– updates to documentation such as the README or other markdown filesstyle
– changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.test
– including new or correcting previous testsperf
– performance improvementsci
– continuous integration relatedbuild
– changes that affect the build system or external dependenciesrevert
– reverts a previous commit