Sub topic 1
Why a Commit Convention Is Worth the Effort
Prerequisites
This chapter assumes you can do the following:
- Use basic Git:
add,commit,log, and branches. - Write a commit message with
git commit -mor in an editor. - Read a version number in the form MAJOR.MINOR.PATCH (Semantic Versioning).
- Run commands in a terminal.
The problem with free-form messages
Git accepts any text as a commit message. That freedom is useful early in a project. Over time it produces a history like this:
update stuff
fix
more changes
Fixed the bug
WIP
Merge branch 'main' into featureEach message made sense to its author on the day they wrote it. Months later, nobody can tell which commits added features, which fixed bugs, and which only touched formatting. Three kinds of work suffer.
- Reading history. A reviewer or new teammate must open each diff to learn what changed.
- Searching history. There is no reliable word to search for. One person writes "fix", another "Fixed", another "bugfix".
- Automating from history. A tool cannot decide whether a release is a patch or a major version if the messages carry no structure.
What a convention gives you
The Conventional Commits specification (version 1.0.0) is a lightweight format for commit messages. Every message starts with a short, predictable prefix that states what kind of change it is. The smallest valid message has a type, a colon, a space, and a description:
fix: prevent crash when the config file is emptyA fuller message can add a scope, a body, and footers. Later chapters cover each part. For now, the point is that the first line is machine-readable and still easy for a person to read.
A consistent prefix lets plain git log filter history by change type:
git log --oneline --grep='^feat'
git log --oneline --grep='^fix'The first command lists commits that added features. The second lists bug fixes. No extra tooling is needed, only agreement on the format.
Where the benefits come from
The convention pays off in four places.
| Benefit | What it means in practice |
|---|---|
| Readable history | `git log --oneline` reads like a summary of the project's changes. |
| Searchable history | You can filter by type, such as `feat` or `fix`, with `--grep`. |
| Clear breaking changes | A marker in the message tells everyone a change may break users. |
| Automation | Tools can compute the next version number and generate a changelog. |
The last two are the reason many teams adopt the convention. Conventional Commits was designed to line up with Semantic Versioning. A fix maps to a PATCH release, a feat maps to a MINOR release, and a breaking change maps to a MAJOR release. A release tool can read the commits since the last tag and pick the right version without a human making that call.
What it costs
A convention is not free. Expect these costs:
- Learning time. Each person must learn the types and the format.
- Discipline. Choosing the right type takes a moment of thought on every commit.
- Friction at first. Messages get rejected, or need rewording, until the habit forms.
You can reduce the cost by enforcing the format automatically. A commit-msg hook or a linter such as commitlint catches mistakes before they reach the shared history. Later chapters show how to set both up.
When it is worth it
The convention pays off most when:
- Several people contribute to the same repository.
- You publish releases that others depend on, such as a library or an API.
- You want changelogs or version numbers produced automatically.
For a solo throwaway script, the effort may not be justified. Even there, the habit is cheap to build, and it makes your own history easier to read later.
What comes next
The next chapter breaks a conventional commit into its parts: type, scope, description, body, and footers. After that, the chapters cover choosing types, marking breaking changes, mapping commits to versions, and enforcing the format.
Exercise
A teammate says, "Our commit messages are fine. We all understand them." Give two concrete problems that free-form messages cause as the project and team grow, and name one thing a consistent prefix like feat: or fix: lets you do that free-form messages do not.
Show answer
Any two of these problems: reviewers must open each diff to learn what changed; searching is unreliable because people word the same idea differently ("fix", "Fixed", "bugfix"); tools cannot decide the next version number or build a changelog from unstructured text. A consistent prefix lets you filter by change type with plain Git, for example git log --oneline --grep='^fix' to list bug fixes. It also lets tools map commits to a PATCH, MINOR, or MAJOR release.
Exercise
Which of these messages is a valid conventional commit, and why are the others not? (a) Fixed the login bug (b) fix: handle expired login tokens (c) fix - handle expired login tokens
Show answer
Only (b) is valid. It has a type (fix), a colon, a space, and a description. (a) has no type or colon. (c) uses a dash instead of a colon, so it does not match the required structure.