Conventional Commits

Conventional Commits

Apr 8, 2022 8:18 AM
Well Documented

Conventional Commits

The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.

Why Use Conventional Commits

Automatically generating CHANGELOGs

Automatically determining a semantic version bump (based on the types of commits landed)

Communicating the nature of changes to teammates, the public, and other stakeholders

Triggering build and publish processes

Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history

Types of conventions

feat: Must be used when a commit adds a new feature to your application or library.

fix: MUST be used when a commit represents a bug fix for your application.

style: Feature and updates related to styling

refactor: Refactoring a specific section of the codebase focused on readability, style and/or performance.

test: Everything related to testing

docs: Everything related to documentation

chore: Regular code maintenance.[You can also use emojis to represent commit types]

HOTFIX: If any urgent fixes are required.


Commits must be prefixed with a type, which consists of a noun, feat, fix, etc., followed by an optional scope, and a required terminal colon and space.

Commit format should be keyword(scope): [ticket-id]

Commit must contain Ticket id.

If custom keywords are used keyword should be in a single word.

A scope may be provided after a type. A scope must consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., fix(parser):

A description must immediately follow the space after the type/scope prefix. The description is a short summary of the code changes, e.g., fix: array parsing issue when multiple spaces were contained in a string.

A longer commit body may be provided after the short description, providing additional contextual information about the code changes. The body must begin with one blank line after the description.

A commit body is free-form and may consist of any number of newline-separated paragraphs.

One or more footers may be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a : or # separator, followed by a string value (this is inspired by the git trailer convention).

A footer’s value may contain spaces and newlines, and parsing must terminate when the next valid footer token/separator pair is observed.

A hotfix must consist of the uppercase text HOTFIX, followed by a colon and a space.

A description must be provided after the HOTFIX:, describing what the change is about, e.g., HOTFIX: environment variables now take precedence over config files.

How to use

Hooks reside in the .git/hooks dir of every git repo. The .sample extension prevents them from executing by default. To install them you need to remove the  .sample  extension.

To make the hook executable you can simply run this command

Once the hook is made an executable copy and pastes the code below, which checks for conventional commit messages.

Pre commit-msg hook

Pre-commit msg hook that checks for conventional-commits