Semantic Commits

What are Semantic Commits?

Semantic commits follow a standardized format for commit messages that clearly communicate the nature of changes.

Conventional Commits Specification

The format is: type(scope): description

Types

Scope (Optional)

A scope can be provided to specify the place of the commit change.

Examples: auth, api, ui, db

Description

A short description of the change.

Body (Optional)

A longer description of the change.

Footer (Optional)

Breaking changes, issues closed, etc.

Examples

feat(auth): add user login functionality

fix(ui): resolve button alignment issue in header

docs(readme): update installation instructions

feat(api)!: change user endpoint response format

fix: prevent racing condition in user service

refactor: extract common code to utils module

Breaking Changes

Mark breaking changes with ! after type or in footer:

feat!: change API response format

feat(api): change response format

BREAKING CHANGE: The API response format has changed

Benefits

Tools and Integration

Commitizen

Interactive tool for creating semantic commits:

npm install -g commitizen

Husky + Commitlint

Enforce semantic commits with Git hooks:

npm install --save-dev @commitlint/cli @commitlint/config-conventional husky

Semantic Release

Automate versioning and releasing:

npm install --save-dev semantic-release

Version Calculation

Best Practices

Implementation

Git Hook Example

Create .git/hooks/commit-msg:

#!/bin/sh
npx --no-install commitlint --edit "$1"

Commitlint Config

.commitlintrc.js:

module.exports = {
  extends: ['@commitlint/config-conventional']
};
Loading