Introduction

Git Commit Convention is a set of rules for writing Git commit messages in a consistent format. It helps developers understand the purpose of a commit and its impact on the codebase, revealing its intention at the commit message. Official Commit Convention

Why Use Git Commit Convention?

  • Clarity: Commit messages are clear and concise, making it easier to understand the changes made in a commit.
  • Consistency: All commit messages follow the same format, making it easier to revert a specific modification.
  • History: A well-formatted commit message provides context about why a change was made, which can be helpful when reviewing code history with the intent of each modification.

In a context of collaboration with other developers, it is important to follow a convention to make the codebase more readable and maintainable.

Structure

Write down the commit with the following format:

git commit -m <title> -m <description>

The title should be a short description of the commit, and the description should provide more context about the changes made.

“If applied, my commit will (INSERT COMMIT MESSAGE TEXT)”

Made a mistake? Edit the commit

This command will modify the last commit, so you can add more changes or fix the commit message.

git commit --amend -m “new commit message” 

Rules

  • Capitalize first word, not end in punctuation
  • Imperative mood. Example - Add dark mod toggle button at navbar
  • Short and direct, no longer than 50 characters
  • what, where, when, why and how

Types

  • feat – a new feature is introduced with the changes
  • fix – a bug fix has occurred
  • chore – changes that do not relate to a fix or feature and don’t modify src or test files (for example updating dependencies)
  • refactor – refactored code that neither fixes a bug nor adds a feature
  • docs – updates to documentation such as a the README or other markdown files
  • style – changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.
  • test – including new or correcting previous tests
  • perf – performance improvements
  • ci – continuous integration related
  • build – changes that affect the build system or external dependencies
  • revert – reverts a previous commit

Examples

feat: improve performance with lazy load implementation for images
chore: update npm dependency to latest version
fix: fix bug preventing users from submitting the subscribe form
fix: Update incorrect client phone number within footer body per client request
Long Example
fix: fix foo to enable bar

This fixes the broken behavior of the component by doing xyz. 

BREAKING CHANGE
Before this fix foo wasn't enabled at all, behavior changes from <old> to <new>

Closes D2IQ-12345