Writing good Git commit messages is crucial for maintaining a clean and understandable version history of your project. Clear commit messages help collaborators understand the purpose of each change and make it easier to review, revert, or analyze the history. Here are some guidelines for writing effective Git commit messages:

1. Separate subject from body

  • Keep the subject line concise (50 characters or less).
  • Add a blank line between the subject and the body.
Short summary (subject)

Detailed explanation (body)

2. Use the imperative mood

  • Start the subject with a verb in the imperative mood (e.g., “Add,” “Fix,” “Update”).
  • This provides a clear instruction on what the commit does.
Add new feature

This commit adds a new feature that allows...

3. Limit the subject line to 50 characters

  • Keep the subject line short and to the point.
  • If more detail is needed, use the body for explanations.

4. Capitalize the subject line

  • Begin the subject with a capital letter.

5. Use the body to explain what and why, not how

  • Explain the reasoning behind the change.
  • Describe any potential side effects or considerations.

6. Wrap the body at 72 characters

  • Keep lines in the body text at a reasonable length for readability.

7. Reference relevant issues

  • If your commit addresses a specific issue, reference it in the message.
Fix issue #123

The commit resolves an issue where...

8. Provide context when necessary

  • If the change is complex or may not be immediately obvious, add context.

Examples

Good Commit Message

Add authentication feature

This commit introduces a new authentication system using OAuth2.0 for user login.
It addresses the issue #456 reported by users who were unable to securely access their accounts.

Poor Commit Message

Changes

This commit makes changes to several files.

By following these guidelines, you contribute to a more understandable and maintainable version history for your project. This becomes especially important as the project grows and more people collaborate on it.

For further information on the subject, I can expressly recommend the article on cbeams. Absolutely worth reading for both beginners and professionals.