Understanding Conventional Commit Messages: A Simple Guide
Table of contents
What are conventional commits?
Conventional commits is a lightweight convention for writing commit messages that follows a specific structure. This structure makes it easier for humans and machines to understand the intent of each commit. It’s especially useful for projects that use automated tools like version control systems and CI/CD pipelines.
The Basic Structure
A Conventional Commit message follows this format:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Type: A keyword that indicates the nature of the change, such as
feat
for new features,fix
for bug fixes, orchore
for miscellaneous tasks.Scope: An optional area of the project where the change was made (e.g.,
feat(api)
).Description: A concise summary of the change.
Body: Additional details about the change, if necessary.
Footers: Extra information, such as
BREAKING CHANGE
to indicate a major change.
Common Types
feat: A new feature
fix: A bug fix
refactor: A code change that neither adds a feature nor fixes a bug
perf: A performance improvement
test: Changes to tests
build: Changes to the build process
chore: Other changes (e.g., documentation, configuration)
Example
`feat(api): Add a new endpoint for retrieving user data
This new endpoint allows users to fetch their profile information using a GET request.`
Why Use Conventional Commits?
Improved Readability: Commit messages become more consistent and easier to understand.
Automated Tools: Many tools can leverage Conventional Commits to automate tasks like generating changelogs, determining version numbers, and triggering CI/CD pipelines.
Better Collaboration: It promotes a common understanding of commit types and makes it easier for contributors to work together effectively.
By adopting Conventional Commits, you can create a more organized and maintainable project history. It's a simple yet powerful practice that can benefit both individual developers and teams.
Subscribe to my newsletter
Read articles from Sunil Kumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Sunil Kumar
Sunil Kumar
Teaching myself how to code