Commit Message Best Practices

Master the art of writing clear, concise commit messages to keep your project history clean and maintainable, ensuring clarity in your codebase and smooth collaboration.

Clear, concise commit messages help maintain a clean, understandable project history. Use the tips below to improve your commit messages.

Avoid adding direct links to platforms like GitLab or GitHub in the main commit message body. This ensures messages remain relevant even if the project changes platforms.

If a link to an issue is necessary, include it in the footer.

Example:

Resolves: #123

Prioritize Conciseness #

Skip articles like a, an, and the in commit messages to make them more direct and concise.

Use Backticks for Technical Terms #

When referring to files, code, or components, enclose them in backticks for clarity.
Example:

fix(ResultView): remove `okButton`

Respect Case Sensitivity #

Always match the exact case and spelling used in the code to avoid confusion.
Example:
Use tableView (if that’s how it appears in the code) instead of UITableView.

Follow Conventional Commit Types #

Use these prefixes to categorize changes:

  • build: Changes to build systems or dependencies.
  • chore: Routine tasks or maintenance.
  • ci: Continuous integration/deployment updates.
  • docs: Documentation updates.
  • feat: New features.
  • fix: Bug fixes.
  • perf: Performance improvements.
  • refactor: Code changes without altering functionality.
  • revert: Reverts a previous commit.
  • style: Code formatting or cosmetic updates.
  • test: Adding or modifying tests.

Structure Commit Messages for Clarity #

Write commit messages using this structure:

<type>[optional scope]: <description>
[optional body]
[optional footer(s)]

Include a scope in parentheses for context when relevant.
If the file you’re working on contains many methods, specify the full path, including the relevant method, for greater clarity.

Examples:

feat(login): add captcha for enhanced security
fix(Coordinator/MoreTab): simplify code

Use the Imperative Mood #

Write commit messages as commands.
Example:

Fix bug // Correct
Fixed bug // Incorrect

Keep Messages Short #

Try to limit commit messages to 72 characters or fewer for better readability and clearer communication.