Understanding Conventional Commits

9 October 2023 · netologist · 3 min, 459 words ·

When working on a project, especially in a team setting, it’s crucial to have a clear and understandable commit history. Enter “Conventional Commits”, a specification for adding human and machine-readable meaning to commit messages.

What are Conventional Commits?

Conventional Commits is a commit message convention that provides an easy set of rules for creating consistent commit messages. It’s a standardized format that makes it simpler to:

The Basic Structure

A conventional commit message consists of a header, and optionally a body and a footer. The header has a special format:

<type>[optional scope]: <description>

[optional body]

[optional footer(s)]
feat(button): add a mute icon to the video button
fix(player): handle user autoplay restrictions
refactor(utils): rework the calculation method
docs(readme): add usage section

Why Use Conventional Commits?

  1. Clarity & Focus: Each commit has a clear purpose, making it easier to review and understand the context.

  2. Automation: Tools like standard-version or semantic-release can use the commit messages to automatically generate changelogs and determine version bumps.

  3. Collaboration: It provides a unified way of committing changes, ensuring that everyone in the team is on the same page.

Common Types

Breaking Changes

Sometimes you might introduce changes that break backward compatibility. These are often denoted with BREAKING CHANGE in the commit footer:

feat(database): change the database schema

BREAKING CHANGE: modifies the database schema which isn't backward compatible.

or appends a ! after the type/scope, introduces a breaking API change (correlating with MAJOR in Semantic Versioning). A BREAKING CHANGE can be part of commits of any type.

Tools Supporting Conventional Commits

Several tools support or advocate for the Conventional Commits specification:

Conclusion

Adopting Conventional Commits can be a game-changer, especially for larger projects or teams. While it might take a bit to get used to, the benefits in terms of clarity, automation, and collaboration are immense. Give it a try and bring consistency and clarity to your commit messages!