Writing a Git Commit Message
This is a summary of Chris Beams’ post on “How to Write a Git Commit Message” for the purpose of being my quick reference. (As Chris mentions: “This has all been said before” - see his references.)
Guidelines
- Separate subject from body with a blank line
- Limit the subject line to 50 characters, with hard limit at 72
- 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
1. Separate subject from body with a blank line
- Blank line separation is needed for some Git commands to work better in short form
- Use a text editor instead of the CLI -m option. To setup an editor for use with Git CLI, see this section of Pro Git.
2. Limit the subject line to 50 characters, with hard limit at 72
- GitHub’s UI truncates any subject line longer than 72 characters with an ellipsis
- Git log one-liner or shortlog works better with approx 50 chars
3. Capitalize the subject line
4. Do not end the subject line with a period
5. Use the imperative mood in the subject line
- Imperative mood means “spoken or written as if giving a command or instruction” e.g. clean your room, or close the door
- A Git commit subject line should be able to complete the following sentence:
- If applied, this commit will your subject line here
- If applied, this commit will refactor subsystem X for readability
6. Wrap the body at 72 characters
7. Use the body to explain what and why vs. how
- Focus on clarifying the reasons why you made the change in the first place — the way things worked before the change and what was wrong with that, the way they work now, and why you decided to solve it the way you did.