Sub topic 1
Why a Commit Convention Is Worth the Effort
Commit messages are the only documentation that travels with every change. Most teams write them without any agreed shape, and the history that results is hard to search, hard to review, and impossible to automate against. This chapter explains what a commit convention fixes, what it costs, and why Conventional Commits is a good candidate. Later chapters cover the format itself in detail.
Prerequisites
This chapter assumes you already have the following:
- Basic Git use:
git add,git commit,git log, and branches. - Experience writing a commit message, either in an editor or with
git commit -m. - A basic idea of Semantic Versioning, the
MAJOR.MINOR.PATCHscheme. - Comfort running commands in a terminal.
You do not need to know the Conventional Commits format yet. This chapter only shows a few examples so the problem and the fix are concrete.
What an unstructured history looks like
Here is a history that most developers will recognize:
a1b2c3d update stuff
e4f5a6b fix
9c8d7e6 more changes
1f2e3d4 WIP
5a6b7c8 Fixed the bug from yesterday
0d9e8f7 changes to login and also added export and cleaned up cssEach message made sense to its author at the time. Six months later, none of them answers the questions a reader actually has:
- What kind of change was this: a new feature, a bug fix, or cleanup?
- Which part of the system did it touch?
- Could it break someone who depends on this code?
- Is it safe to ship, or does it need a migration?
The last message also shows a second problem. It bundles three unrelated changes (login, export, CSS) into one commit, and the message gives no signal that this happened.
What a convention changes
A commit convention is an agreement about the shape of a message. The shape matters more than the exact wording, because a predictable shape can be read by people and by programs.
Here is the same kind of history after adopting Conventional Commits:
fix(login): reject expired session tokens
feat(export): add CSV export for reports
style(css): align spacing in the settings page
refactor(auth): extract token validation helper
fix: prevent crash when the config file is emptyEvery line starts with a type (fix, feat, style, refactor), optionally followed by a scope in parentheses, then a colon and a short description. You can tell what happened without opening a diff.
Four benefits you can measure
Readable history
A reader scanning git log --oneline can skip whole categories. If you are hunting for a regression, you look at fix lines. If you are preparing release notes, you look at feat lines. Reviewers also benefit, because a message that says refactor sets the expectation that behavior does not change, and the diff can be read with that in mind.
Searchable history
A consistent prefix turns plain git log into a filter. No extra tooling is required:
git log --oneline --grep='^feat'
git log --oneline --grep='^fix'The ^ anchors the match to the start of the message, so a commit that merely mentions the word "fix" in its description is not returned. With scopes, you can narrow further, for example --grep='^fix(login)'.
Reviewable pull requests
When every commit has a type, mixed-purpose commits become visible. A commit you want to label feat and fix and style at once is a commit that should have been split. The convention therefore nudges authors toward small, single-purpose commits, which are easier to review, easier to revert, and easier to bisect.
Automatable releases
This is the benefit that justifies the effort for many teams. If the type of every change is machine-readable, tools can:
- Decide the next version number.
- Generate a changelog grouped by type.
- Fail a build when a message does not follow the rules.
- Flag breaking changes to downstream users.
The connection to Semantic Versioning is direct. A fix corresponds to a PATCH release, a feat corresponds to a MINOR release, and a breaking change corresponds to a MAJOR release. A later chapter covers this mapping precisely. For now, the point is that without a convention, a tool cannot know which of your commits is which.
Why Conventional Commits specifically
Teams can invent their own convention, and some do. Conventional Commits 1.0.0 is worth choosing over a private format for three reasons.
- It is small. The core rule is one line: a type, an optional scope, a colon, a space, and a description. Body and footers are optional.
- It is designed around Semantic Versioning. The meaning of
feat,fix, and breaking changes is defined by the specification, so the version arithmetic is not up to each team. - Tooling already exists. Linters, changelog generators, and release tools understand the format. A private format means writing and maintaining all of that yourself.
Here is the smallest valid message, and a fuller one:
fix: prevent crash when the config file is emptyfeat(parser): add support for array literals
The parser now accepts [1, 2, 3] syntax and produces an ArrayNode.
Refs: #482The second example adds a scope (parser), a body separated by a blank line, and a footer. Each part is introduced in the next chapter.
What it costs
A convention is not free, and an honest assessment helps you decide whether to adopt it.
| Cost | What it looks like in practice |
|---|---|
| Learning curve | Each contributor must learn the types and when to use each one. |
| Friction per commit | Writing `type(scope): ` takes a few extra seconds and some thought. |
| Judgment calls | Is a change a `refactor` or a `perf`? Is it `fix` or `feat`? Teams will disagree at first. |
| Enforcement setup | Hooks or CI checks need to be installed and maintained. |
| Pressure on commit size | Authors must split mixed commits or accept a vague type. |
The judgment calls deserve attention. The convention does not remove ambiguity. It moves the ambiguity to a single, visible decision made at commit time, when the author knows the most about the change. That is a better time to decide than six months later during a release.
When the effort is not worth it
The convention pays off in proportion to how many people and tools read your history. Consider skipping or relaxing it in these cases:
- A throwaway prototype or personal scratch repository that no one else will read.
- A repository where every change lands through squash merges and the team only controls the pull request title. In that case you apply the convention to the title rather than to every commit. A later chapter covers this workflow.
- A team that has no release process and no plan to generate changelogs, and that is already satisfied with its history.
Even then, a lightweight habit of starting messages with a type costs almost nothing and keeps the option open.
What a convention does not do
Setting expectations avoids disappointment during adoption.
- It does not make messages good.
fix: stuffis valid format and useless content. A later chapter on writing descriptions covers this. - It does not replace a changelog review. Generated changelogs are only as clear as the messages behind them. Someone should still read them before a release.
- It does not retroactively fix old history. Rewriting shared history is risky. Most teams adopt the convention from a chosen date forward.
- It does not decide your versioning policy. It gives you the vocabulary. You still decide what counts as a breaking change for your users.
Common mistakes at the start
Several problems appear in almost every first week of adoption:
- Using
featfor everything. Afeatimplies aMINORrelease. Labeling a typo fix asfeatinflates version numbers and pollutes the changelog. - Inventing types on the fly. Types such as
updateormisccarry no agreed meaning. Stick to the set your team has agreed on. - Skipping enforcement. Without a hook or a CI check, compliance drifts within weeks. Enforcement is covered in a later chapter.
- Mixing several changes in one commit. The convention exposes this, but it does not prevent it. Split the commit.
- Treating the format as the goal. The goal is a history that people can read and tools can trust.
Putting it together
A commit convention is a small, shared agreement that gives every message a predictable shape. That shape improves reading, searching, and reviewing, and it makes automation of versioning and changelogs possible. The costs are a learning curve, a few seconds per commit, and some setup for enforcement. For any repository that several people read, or that publishes versions, the trade is favorable.
Exercise
A teammate says, "Our commit messages are fine. Everyone writes something sensible." Name two concrete things a tool could not do with free-form messages that it can do with Conventional Commits, and explain why.
Show answer
Examples include choosing the next Semantic Versioning bump automatically and generating a changelog grouped by change type. Free-form messages have no machine-readable marker for whether a change is a feature, a fix, or a breaking change, so a tool would have to guess from natural language. With Conventional Commits, the type prefix (feat, fix) and the breaking-change markers give the tool exact signals. Filtering history with git log --grep='^feat' is another example.
Exercise
You find this commit: feat: fix typo in README and add CSV export and rename two variables. List the problems from the point of view of the convention, and say how you would fix the history going forward.
Show answer
The commit bundles three unrelated changes, so no single type is accurate. It also labels a typo fix and a rename as feat, which would wrongly suggest a MINOR release for them, and the long description is hard to scan. Going forward, split the work into separate commits, for example docs: fix typo in README, feat(export): add CSV export, and refactor: rename two variables. Do not rewrite shared history that has already been pushed. Apply the split from the next change onward.
Exercise
Which of these commands lists only commits whose message starts with the word "fix", and why does the ^ matter?
1. git log --oneline --grep='fix'
2. git log --oneline --grep='^fix'
Show answer
Command 2. The ^ anchors the pattern to the start of the message, so only commits whose first characters are "fix" match. Command 1 also returns any commit that mentions "fix" anywhere, such as feat: add prefix handling, which contains "fix" inside the word "prefix".