Conventional Commits
Conventional Commits is a specification for adding human and machine-readable meaning to commit messages. This format enhances the readability and understanding of the history of changes within software projects, particularly those employing version control systems like Git. Here are some key aspects:
History and Context
The specification for Conventional Commits was developed to provide a standardized way to format commit messages. It was inspired by various commit message guidelines already in use, such as those from Angular, which had its own commit message convention for a long time. The Conventional Commits format was formalized to:
- Provide an easily understandable commit history.
- Automate the generation of Changelogs.
- Enable automated semantic versioning (SemVer).
Structure
A commit message following the Conventional Commits specification has the following structure:
- Type: Specifies the type of change (e.g., 'fix', 'feat', 'docs', 'style', 'refactor', 'test', 'chore').
- Scope (Optional): A section of the codebase enclosed in parenthesis, e.g., '(core)'.
- Subject: A brief description of the change in the imperative mood.
- Body (Optional): A more detailed explanation of what and why was changed.
- Footer (Optional): Contains additional metadata like Breaking Change notices or references to issues.
Example
fix(core): correct minor typos in code
- See the misspelling of 'environment'
- Fix typo in 'development'
BREAKING CHANGE: This commit introduces a breaking change in the API for the environment variable.
Benefits
- Improved Readability: Developers can quickly understand the nature of changes at a glance.
- Automation: Tools can parse commit messages to generate changelogs, update versions, or trigger CI/CD pipelines.
- Documentation: It supports the generation of project documentation by providing structured commit history.
Implementation
Various tools and libraries support or enforce Conventional Commits in different programming ecosystems:
- Commitizen: A command-line tool for creating commits in a standardized format.
- Husky and Lint-Staged: Git hooks to enforce commit message format.
- semantic-release: Automates versioning and package publishing based on commit messages.
External Links
Here are some related topics: