Skip to content

Conventional Commits

A specification and convention for structuring version control commit messages to convey meaning for both people and tools alike.

Provides an easy to use form that supports creating an explicit change history, as well as enabling tool automation for that history.

Using a consistent set of change types flattens the learning curve when contributing to the project.

The Conventional Commits specification includes the following elements:

  • Type: Indicates the nature of the change (e.g., feat, fix, docs).
  • Scope (optional): Specifies the area of the codebase affected.
  • Description: A brief summary of the change.
  • Body (optional): Additional details about the change.
  • Footer (optional): References to issues or breaking changes.

General form of a conventional commit message

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]

Breaking changes are marked with ! after the type/scope, or including BREAKING CHANGE: <description> as the last line (footer) of the commit message body.

Conventional Commits web page

Change Types

  • build changes affecting the build system or external dependencies
  • chore
  • ci continuous integration change, e.g. Git workflows and pipelines
  • docs add or update documentation to the project
  • feat relates to a feature of the project
  • fix resolves a specific bug or issue in the source code
  • perf performance related change
  • refactor change to the design, architecture, language, library or tooling
  • style changes not affecting the meaning of the code (blank-space, formatting, etc)
  • revert reverts a previous commit. Use the description from the reverted commit, the body it should state: This reverts commit <hash>, where hash is the SHA of the commit being reverted.
  • test testing the project, e.g. unit & integration testing

A project could introduce more types, if there is significant value and their purpose is documented in the projects contribution guide.

Body

The body should include the motivation for the change and contrast this with previous behavior.

Use the imperative, present tense: "change" not "changed" nor "changes".

The footer should contain any information about related issue tickets or breaking changes.

Reference an issue using either Related or Resolve, followed by a reference to the issue, e.g. resolve: #42

BREAKING CHANGE: when a commit introduces a breaking API change or any impactful change to users of the project.

Breaking Changes should start with the word BREAKING CHANGE: with a space or two newlines. The rest of the commit message is then used for this.

Other footers can follow a convention similar to git trailer key/value format.

Include footer tags in a commit message template
# resolve: #
# related: #
# BREAKING CHANGE: <brief description>

Tool support

Git Hook

Pre-receive hook for conventional commits
.git/hooks/pre-receive
#!/usr/bin/env bash

# Pre-receive hook that will block commits with messages that do not follow regex rule

commit_msg_type_regex='feat|fix|refactor|style|test|docs|build'
commit_msg_scope_regex='.{1,20}'
commit_msg_description_regex='.{1,100}'
commit_msg_regex="^(${commit_msg_type_regex})(\(${commit_msg_scope_regex}\))?: (${commit_msg_description_regex})\$"
merge_msg_regex="^Merge branch '.+'\$"

zero_commit="0000000000000000000000000000000000000000"

# Do not traverse over commits that are already in the repository
excludeExisting="--not --all"

error=""
while read oldrev newrev refname; do
  # branch or tag get deleted
  if [ "$newrev" = "$zero_commit" ]; then
    continue
  fi

  # Check for new branch or tag
  if [ "$oldrev" = "$zero_commit" ]; then
    rev_span=`git rev-list $newrev $excludeExisting`
  else
    rev_span=`git rev-list $oldrev..$newrev $excludeExisting`
  fi

  for commit in $rev_span; do
    commit_msg_header=$(git show -s --format=%s $commit)
    if ! [[ "$commit_msg_header" =~ (${commit_msg_regex})|(${merge_msg_regex}) ]]; then
      echo "$commit" >&2
      echo "ERROR: Invalid commit message format" >&2
      echo "$commit_msg_header" >&2
      error="true"
    fi
  done
done

if [ -n "$error" ]; then
  exit 1
fi

Gitmojis

Visual indicators make browsing the commit history easier for a human to filter.

Commonly used Gitmojis from Conventional-Commits.nvim

New / Updates:

  • ๐ŸŽ‰ :tada: Begin a project.
  • โœจ :sparkles: Introduce new features.
  • ๐Ÿšฉ :triangular_flag_on_post: Add, update, or remove feature flags.
  • ๐Ÿ’„ :lipstick: Add or update the UI and style files.
  • ๐Ÿ›‚ :passport_control: Work on code related to authorization, roles and permissions.
  • โฌ†๏ธ :arrow_up: Upgrade dependencies.
  • โž• :heavy_plus_sign: Add a dependency.
  • ๐Ÿ”ง :wrench: Add or update configuration files.
  • ๐Ÿ”จ :hammer: Add or update development scripts.
  • ๐Ÿš€ :rocket: Deploy stuff.
  • ๐Ÿ”– :bookmark: Release / Version tags.
  • โœ… :white_check_mark: Add, update, or pass tests.
  • ๐Ÿ”’๏ธ :lock: Fix security or privacy issues.
  • โ™ป๏ธ :recycle: Refactor code.
  • โšฐ๏ธ :coffin: Remove dead code.
  • ๐Ÿ™ˆ :see_no_evil: Add or update a .gitignore file.

Corrections:

  • ๐Ÿ”ฅ :fire: Remove code or files.
  • ๐Ÿ› :bug: Fix a bug.
  • ๐Ÿš‘๏ธ :ambulance: Critical hotfix.

Docs:

  • ๐Ÿ“ :memo: Add or update documentation.
  • โœ๏ธ :pencil2: Fix typos.
Gitmojis for Conventional Commits

conventional-commits.nvim Gitmojis.json

  • ๐ŸŽจ :art: I`mprove structure / format of the code.
  • โšก๏ธ :zap: Improve performance.
  • ๐Ÿ”ฅ :fire: Remove code or files.
  • ๐Ÿ› :bug: Fix a bug.
  • ๐Ÿš‘๏ธ :ambulance: Critical hotfix.
  • โœจ :sparkles: Introduce new features.
  • ๐Ÿ“ :memo: Add or update documentation.
  • ๐Ÿš€ :rocket: Deploy stuff.
  • ๐Ÿ’„ :lipstick: Add or update the UI and style files.
  • ๐ŸŽ‰ :tada: Begin a project.
  • โœ… :white_check_mark: Add, update, or pass tests.
  • ๐Ÿ”’๏ธ :lock: Fix security or privacy issues.
  • ๐Ÿ” :closed_lock_with_key: Add or update secrets.
  • ๐Ÿ”– :bookmark: Release / Version tags.
  • ๐Ÿšจ :rotating_light: Fix compiler / linter warnings.
  • ๐Ÿšง :construction: Work in progress.
  • ๐Ÿ’š :green_heart: Fix CI Build.
  • โฌ‡๏ธ :arrow_down: Downgrade dependencies.
  • โฌ†๏ธ :arrow_up: Upgrade dependencies.
  • ๐Ÿ“Œ :pushpin: Pin dependencies to specific versions.
  • ๐Ÿ‘ท :construction_worker: Add or update CI build system.
  • ๐Ÿ“ˆ :chart_with_upwards_trend: Add or update analytics or track code.
  • โ™ป๏ธ :recycle: Refactor code.
  • โž• :heavy_plus_sign: Add a dependency.
  • โž– :heavy_minus_sign: Remove a dependency.
  • ๐Ÿ”ง :wrench: Add or update configuration files.
  • ๐Ÿ”จ :hammer: Add or update development scripts.
  • ๐ŸŒ :globe_with_meridians: Internationalization and localization.
  • โœ๏ธ :pencil2: Fix typos.
  • ๐Ÿ’ฉ :poop: Write bad code that needs to be improved.
  • โช๏ธ :rewind: Revert changes.
  • ๐Ÿ”€ :twisted_rightwards_arrows: Merge branches.
  • ๐Ÿ“ฆ๏ธ :package: Add or update compiled files or packages.
  • ๐Ÿ‘ฝ๏ธ :alien: Update code due to external API changes.
  • ๐Ÿšš :truck: Move or rename resources (e.g.: files, paths, routes).
  • ๐Ÿ“„ :page_facing_up: Add or update license.
  • ๐Ÿ’ฅ :boom: Introduce breaking changes.
  • ๐Ÿฑ :bento: Add or update assets.
  • โ™ฟ๏ธ :wheelchair: Improve accessibility.
  • ๐Ÿ’ก :bulb: Add or update comments in source code.
  • ๐Ÿป :beers: Write code drunkenly.
  • ๐Ÿ’ฌ :speech_balloon: Add or update text and literals.
  • ๐Ÿ—ƒ๏ธ :card_file_box: Perform database related changes.
  • ๐Ÿ”Š :loud_sound: Add or update logs.
  • ๐Ÿ”‡ :mute: Remove logs.
  • ๐Ÿ‘ฅ :busts_in_silhouette: Add or update contributor(s).
  • ๐Ÿšธ :children_crossing: Improve user experience / usability.
  • ๐Ÿ—๏ธ :building_construction: Make architectural changes.
  • ๐Ÿ“ฑ :iphone: Work on responsive design.
  • ๐Ÿคก :clown_face: Mock things.
  • ๐Ÿฅš :egg: Add or update an easter egg.
  • ๐Ÿ™ˆ :see_no_evil: Add or update a .gitignore file.
  • ๐Ÿ“ธ :camera_flash: Add or update snapshots.
  • โš—๏ธ :alembic: Perform experiments.
  • ๐Ÿ”๏ธ :mag: Improve SEO.
  • ๐Ÿท๏ธ :label: Add or update types.
  • ๐ŸŒฑ :seedling: Add or update seed files.
  • ๐Ÿšฉ :triangular_flag_on_post: Add, update, or remove feature flags.
  • ๐Ÿฅ… :goal_net: Catch errors.
  • ๐Ÿ’ซ :dizzy: Add or update animations and transitions.
  • ๐Ÿ—‘๏ธ :wastebasket: Deprecate code that needs to be cleaned up.
  • ๐Ÿ›‚ :passport_control: Work on code related to authorization, roles and permissions.
  • ๐Ÿฉน :adhesive_bandage: Simple fix for a non-critical issue.
  • ๐Ÿง :monocle_face: Data exploration/inspection.
  • โšฐ๏ธ :coffin: Remove dead code.
  • ๐Ÿงช :test_tube: Add a failing test.
  • ๐Ÿ‘” :necktie: Add or update business logic.
  • ๐Ÿฉบ :stethoscope: Add or update healthcheck.
  • ๐Ÿงฑ :bricks: Infrastructure related changes.
  • ๐Ÿง‘โ€๐Ÿ’ป :technologist: Improve developer experience.
  • ๐Ÿ’ธ :money_with_wings: Add sponsorships or money related infrastructure.
  • ๐Ÿงต :thread: Add or update code related to multithreading or concurrency.
  • ๐Ÿฆบ :safety_vest: Add or update code related to validation.
  • โœˆ๏ธ :airplane: Improve offline support.
  • ๐Ÿฆ– :t-rex: Code that adds backwards compatibility.