DEV Community

Thiago Marinho
Thiago Marinho

Posted on

Commit Message Patterns: Write Better Git History

Type: What kind of change (see below).
Scope (optional): What’s affected (e.g., auth, ui, docs).
Description: Short, present-tense summary (50-72 chars).
Body (optional): More details, why it’s done.
Footer (optional): Metadata like "Fixes #123" or "BREAKING CHANGE"

Image description

Common Types of Commit Messages

Here’s a quick reference table for the most frequently used commit types in Conventional Commits:

Type Use Case Example
feat New feature feat(ui): add dark mode toggle
fix Bug fix fix(auth): resolve token expiry
docs Documentation updates docs(readme): update install steps
style Formatting, no logic change style(css): adjust padding
refactor Code cleanup, no behavior change refactor(api): simplify fetch
test Add or update tests test(unit): cover login edge cases
chore Maintenance (deps, tools) chore(deps): update lodash
perf Performance improvement perf(db): optimize query
ci CI/CD changes ci(pipeline): add lint step
build Build system changes build(webpack): minify output
revert Revert a previous commit revert: undo feat(ui)

How to Use This Table

  • Type: Start your commit with one of these keywords.
  • Scope (optional): Add in parentheses (e.g., ui, auth) to specify the area of change.
  • Description: Keep it short, present tense, and descriptive.

Cheat Sheet Examples

Simple Feature

feat(api): add user profile endpoint
Enter fullscreen mode Exit fullscreen mode

Fix with Details

fix(cart): prevent duplicate items
- Added check for existing item ID
- Fixes #45
Enter fullscreen mode Exit fullscreen mode

Breaking Change

feat(auth): switch to JWT tokens
- Replaced session cookies with JWT
BREAKING CHANGE: Old tokens invalid
Enter fullscreen mode Exit fullscreen mode

Chore

chore(deps): bump react to 18.3.0
Enter fullscreen mode Exit fullscreen mode

Refactor

refactor(utils): extract logger to module
Enter fullscreen mode Exit fullscreen mode
  • Improves reusability across files

Tips

  • Scope: Keep it lowercase, short (e.g., ui, server).
  • Breaking Changes: Flag with ! after type (e.g., feat(ui)!: redo layout) or note in footer.
  • Tools: Use with semantic versioning or changelog generators (e.g., standard-version).

Top comments (0)