The Conventional Commits Specification is a lightweight convention on top of commit messages which provides an easy set of rules for creating an explicit commit history, making it easier to write automated tools on top of your codebase. This convention agrees with Semantic Versioning, by describing the features, fixes, and breaking changes made in those commits.
According to this specification, a commit message should be structured as follows:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Let's look at each of these structural element below!
Every commit message should be prefixed with a term that describes in one word the type of change involved in a commit. These prefixes can be one of the types below:
feat:
a new feature is introduced with the changesfix:
a bug fix has occurredchore:
changes that do not relate to a fix or feature and don't modify src or test files (for example updating dependencies)refactor:
refactored code that neither fixes a bug nor adds a featuredocs:
updates to documentation such as a the README or other markdown filesstyle:
changes that do not affect the meaning of the code, likely related to code formatting such as white-space, missing semi-colons, and so on.test:
including new or correcting previous testsperf:
performance improvementsci:
continuous integration relatedbuild:
changes that affect the build system or external dependenciesrevert:
reverts a previous commit
Following the commit type, the description is a short subject line should be a short description written in all lowercase with a character limit to encourage concise, succinct descriptions.
The commit body can contain a more detailed explanation about the commit. We can these details as Markdown as well.
The footers may contain further details about a commit, including external links, Issue# Refs, or Author details, etc.
In addition to these details, a commit footer can have an optional type called BREAKING CHANGE:
which is same as !
after the type(scope): commit prefix (e.g. fix!:
), indicating a breaking change.
NOTE: A BREAKING_CHANGE
can be part of commits of any type.
Conventional Commits help achieve the following things:
- 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
The structural elements in a Commit Message are useful to communicate intent for Semantic Versioning. For example:
- A commit of the type
fix
patches a bug in your codebase. This correlates withPATCH
in Semantic Versioning - A commit of the type
feat
introduces a new ferature to the codebase. This correlates withMINOR
in Semantic Versioning - A commit which includeas a footer with the optional type
BEAKING_CHANGE:
along with a prefix type likefeat:
orfix:
, or an!
appended to the<type+(optional_scope)
prefix likefix!
, introduces a breaking API change. This correlates withMAJOR
in Semantic Versioning.
Let's see some examples of some hypothetical conventional commit messages.
feat: allow provided config object to extend other configs
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
feat!: send an email to the customer when a product is shipped
feat(api)!: send an email to the customer when a product is shipped
chore!: drop support for Node 6
BREAKING CHANGE: use JavaScript features not available in Node 6.
docs: correct spelling of CHANGELOG
feat(lang): add Polish language
fix: prevent racing of requests
Introduce a request id and a reference to latest request. Dismiss
incoming responses other than from latest request.
Remove timeouts which were used to mitigate the racing issue but are
obsolete now.
Reviewed-by: Z
Refs: #123
That's all! Now you have everything that you need to know to start using the Conventional Commits Specification in your Git contributions on your project. With this simple upgrade, you can now create more meaningful commits, which convey the most information to all the members involved, allowing everyone to clearly follow the development of the project over time and space.
If you want to read the full specifications list, you can find it in the Conventional Commits Specification page here.
Thank you for reading... 🙏