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
Breaking changes are marked with ! after the type/scope, or including BREAKING CHANGE: <description> as the last line (footer) of the commit message body.
Change Types¶
buildchanges affecting the build system or external dependencieschorecicontinuous integration change, e.g. Git workflows and pipelinesdocsadd or update documentation to the projectfeatrelates to a feature of the projectfixresolves a specific bug or issue in the source codeperfperformance related changerefactorchange to the design, architecture, language, library or toolingstylechanges not affecting the meaning of the code (blank-space, formatting, etc)revertreverts 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.testtesting 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".
Footer¶
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
Tool support¶
- Neovim: conventional-commits.nvim
Git Hook¶
Pre-receive hook for conventional commits
#!/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.