Commit Message Standards

Master the art of writing clear, meaningful commit messages

Learning Objectives

  • Learn the standardized commit message format
  • Understand how to write clear and descriptive commit messages
  • Master atomic commits and their importance
  • Implement effective commit organization strategies

Writing Great Commit Messages

Clear, well-structured commit messages are crucial for maintaining a useful Git history. They help team members understand changes, make code reviews easier, and facilitate future maintenance.

Benefits

  • Easier code review process
  • Better release notes generation
  • Simplified debugging and bug tracking

Key Principles

  • Be clear and descriptive
  • Follow consistent format
  • Separate subject from body

Commit Message Format

A well-structured commit message follows a standard format that includes a subject line and an optional body separated by a blank line.

Standard Commit Message Format
type(scope): subject line
[optional body]
[optional footer]

Common Types

  • feat:New feature additions
  • fix:Bug fixes
  • docs:Documentation changes
  • style:Code style changes
  • refactor:Code refactoring
  • test:Adding or modifying tests

Commit Message Examples

Feature Addition

feat(auth): add OAuth2 authentication
Implement OAuth2 authentication flow with Google and GitHub providers.
- Add OAuth2 client configuration
- Implement callback handlers
- Add user profile fetching
Closes #123

Bug Fix

fix(api): prevent duplicate user registration
Add unique constraint to email field and proper error handling
for duplicate registration attempts.
Fixes #456

Breaking Change

feat(api)!: change authentication endpoint structure
Change /auth/login to /api/v2/auth for API versioning.
BREAKING CHANGE: Authentication endpoints have moved to /api/v2/auth.
Update your API clients accordingly.

Atomic Commits

Atomic commits contain a single logical change to your codebase. This practice makes it easier to understand changes, revert if needed, and maintain a clean history.

Good Practices

  • One logical change per commit
  • All tests pass with each commit
  • Clear, focused commit messages

Bad Practices

  • Multiple unrelated changes
  • Mixing refactoring with features
  • Vague commit messages

Commit Organization Tips

  • 1.

    Use Interactive Staging

    Use `git add -p` to stage specific parts of files, enabling more granular commits.

    $ git add -p
  • 2.

    Review Changes Before Committing

    Always review staged changes before committing.

    $ git diff --staged
  • 3.

    Fix Up Commits During Development

    Use `--fixup` to mark commits as fixes to previous ones.

    $ git commit --fixup=HEAD~1

What's Next?

Now that you understand commit message standards, let's explore different team workflows and how to choose the right one for your project. In the next lesson, you'll learn about:

  • Common team workflow patterns
  • Trunk-based development strategy
  • Feature branch workflow variations
  • Choosing the right workflow for your team