I created this note on my personal blog to share some patterns and ways I commonly follow to write my Git commit messages.
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>
See an example of commit below:
[type](optional scope): [subject] [optional body] [optional footer]
Must be one of the following:
- build - Build related changes
- ci - CI related changes
- chore - Build process or auxiliary tool changes
- docs - Documentation only changes
- feat - A new feature
- fix - A bug fix
- perf - A code change that improves performance
- refactor - A code change that neither fixes a bug or adds a feature
- revert - Reverting things
- style - Markup, white-space, formatting, missing semi-colons...
- test - Adding missing tests
A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., feat(parser): add the ability to parse arrays.
The subject contains a succinct description of the change:
- Use the imperative, present tense: "change" not "changed" nor "changes"
- No dot (.) at the end.
Just as in the subject, use the imperative, present tense: "change" not "changed" nor "changes". The body should include the motivation for the change and contrast this with previous behavior.
- Separate subject from the body with a blank line
- Limit the subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line
- Wrap the body at 72 characters
- Use the body to explain what and why vs. how