Sub topic 13
Common Mistakes and Tips for Adopting the Convention
This chapter assumes you have read the earlier chapters. You should know the message structure (type, scope, description, body, footers) and the ! and BREAKING CHANGE markers. You should also know how types map to Semantic Versioning, and how a commit-msg hook or commitlint enforces the format. Here we collect the mistakes teams make most often and a plan for introducing the convention without friction.
Mistakes in the message itself
Most problems come from the same few habits. The table lists the ones you will see in code review.
| Mistake | Example | Why it hurts | Fix |
|---|---|---|---|
| Wrong type | `feat: fix typo in error text` | A `feat` triggers a MINOR release for a change that adds nothing. | Use `fix` if the text was wrong, or `docs` if it is documentation. |
| Vague description | `fix: bug` or `chore: updates` | The changelog entry says nothing. | Name the symptom: `fix: prevent crash when the config file is empty`. |
| Several changes in one commit | `feat: add export and fix login redirect` | One type cannot describe both, and a revert undoes both. | Split into two commits. |
| Missing blank line before the body | Body text directly under the first line | Parsers may treat the body as part of the description. | Leave exactly one empty line between header and body. |
| Malformed footer | `Breaking change - clients must upgrade` | Tools only recognize `BREAKING CHANGE: ` and `token: value` footers. | Write `BREAKING CHANGE: clients must upgrade`. |
| Lowercase footer token | `breaking change: ...` | The specification requires `BREAKING CHANGE` in uppercase. | Use uppercase, or use `!` before the colon. |
| Scope that drifts | `feat(auth)`, `feat(authentication)`, `feat(login)` | Filtering by scope returns partial results. | Keep an agreed list of scopes. |
| Past tense or trailing period | `fix: Fixed the crash.` | Not forbidden by the specification, but inconsistent and often rejected by lint rules. | Use imperative mood: `fix: handle empty config`. |
Choosing between feat, fix, and refactor
The most common doubt is which type applies when a change touches behavior only slightly. The diagram gives a decision order. Work through it from the top and stop at the first "yes".
Note the last step. Any type can carry a breaking change, not only feat and fix. A refactor that renames a public function is a breaking change, and it should say so.
Mistakes in enforcement
A convention that is only written down decays within weeks. A convention enforced in only one place gets bypassed. These are the usual gaps.
Hooks that nobody else has
Files in .git/hooks are not committed, so a teammate who clones the repository gets no hook. Store the hook inside the repository and point Git at it:
mkdir -p .githooks
cp .git/hooks/commit-msg .githooks/commit-msg
chmod +x .githooks/commit-msg
git config core.hooksPath .githooks
git add .githooks
git commit -m "build: share commit-msg hook through core.hooksPath"core.hooksPath is a local setting, so each developer still has to run the git config line once. Put it in a setup script or the contributing guide. Tools such as Husky automate this step for Node projects.
Messages Git writes for you
Git generates Merge branch 'x' into main for merge commits and Revert "feat: ..." for git revert. Neither matches the pattern. You have two options: let the hook skip merge messages, or ask contributors to avoid merge commits by rebasing. This version of the hook skips merges only:
#!/bin/sh
# .githooks/commit-msg (must be executable)
first_line=$(head -n 1 "$1")
case "$first_line" in
Merge\ *) exit 0 ;;
esac
pattern='^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9._-]+\))?!?: .+'
if ! printf '%s\n' "$first_line" | grep -Eq "$pattern"; then
echo "Commit message must look like: type(scope)!: description" >&2
exit 1
fiRevert messages are not skipped, so the author is forced to rewrite Revert "feat: add export" as revert: add export and add a Refs: footer with the reverted hashes.
Bypasses and gaps
git commit --no-verifyskips thecommit-msghook. A local hook is a convenience, not a guarantee. Always repeat the check in CI.- Linting only the latest commit misses earlier commits in a branch. Lint the whole range instead:
npx commitlint --from origin/main --to HEAD. - A shallow clone in CI may not contain
origin/main, and the range then fails with an unknown revision. Fetch full history (for example,fetch-depth: 0in GitHub Actions) for that job. - Checking commits but not the pull request title is a gap if you squash merge. See the next section.
Mistakes with squash merges
With squash merging, the commit that lands on the main branch is made from the pull request, not from your individual commits. What the final message contains depends on the repository's settings. On GitHub it can be the PR title, or the single commit's message when the PR has one commit. If the title is Update stuff, your carefully written branch commits do not matter, because history on main will contain Update stuff.
Validate the title in CI. commitlint reads a message from standard input, so a small job can check it. Pass the title through an environment variable, not by pasting it into the command, so that quotes or $(...) in a title cannot run as shell code:
# PR_TITLE is set from the pull request event by your CI system
printf '%s\n' "$PR_TITLE" | npx commitlintTwo related tips:
- Put
BREAKING CHANGE:text in the PR description body if your squash setting copies the description into the commit body. Check what your host actually produces by merging a test PR. - Decide whether branch commits must be conventional at all. Many teams require it only for the PR title. That lowers the cost of adoption, because contributors can commit freely on a branch and a reviewer fixes one line at merge time.
Mistakes with automation
Release tools read the history literally. Three failure modes appear after the first automated release.
- A wrong bump. A mislabeled
featpublishes a MINOR version. Published versions cannot be unpublished safely, so catch this in review before merging. - A missing bump. A fix typed as
choreproduces no release. The bug stays unreleased until some other commit triggers one. - A rewritten history. If you amend or rebase commits that a release tool already processed, it may create duplicate changelog entries or compute the wrong next version. Do not rewrite history on protected branches.
Changelogs also reflect your descriptions directly. If entries read like fix: stuff, the generated notes are useless. Write the description for a reader who has not seen the code, because that reader is whoever opens the release notes.
Tips for adopting the convention
Start small
A new convention succeeds when it is easy to remember. Begin with the types feat, fix, docs, refactor, test, ci, and chore, and add perf, build, and style only when someone asks. Write the list of allowed scopes in the contributing guide, and keep it short.
Reduce typing friction
A commit template shows the rules inside the editor at the moment of writing. Lines starting with # are removed from the final message by default.
# type(scope)!: description (imperative, no period, about 50-72 characters)
#
# Body: explain why the change was made, not what the diff shows.
#
# Footers, one per line:
# Refs: #123
# BREAKING CHANGE: describe what users must changeSave it as .gitmessage in the repository root, then run:
git config commit.template .gitmessageRoll out in stages
- Agree on types and scopes in a short team discussion, and write them down.
- Add commitlint to CI in report-only mode, so failures are visible but do not block merges.
- Add the shared
commit-msghook and the PR title check. - After a couple of weeks, make the CI check required.
- Add changelog or release automation last, once messages are consistently good.
Leave old history alone
Do not rewrite existing commits to match the convention. Rewriting changes every hash after it, and everyone must reset their clones. Start the convention from a chosen date and configure tools to read history from the last release tag onward.
Exercise
A team squash merges every pull request. Their commits on feature branches are all conventional, and commitlint passes in CI. Yet the main branch history contains messages like Update login page (#214). What is missing, and what is a safe way to add it?
Show answer
Nothing validates the PR title, and with squash merging the title (or the single commit message, depending on settings) becomes the commit on main. Add a CI job that checks the title with commitlint, passing it through an environment variable, for example printf '%s\n' "$PR_TITLE" | npx commitlint. Using the variable avoids shell injection from quotes or $(...) in a title. Make that job required for merging.
Exercise
A developer fixes a crash on startup and writes chore: handle null config. The team uses automated releases where only feat and fix create a release. What happens, and how should the message read?
Show answer
No release is created from that commit, so the fix stays unpublished until some other feat or fix commit lands. The message should be fix: handle null config, or more specifically fix: prevent crash when the config file is empty, because the change corrects behavior users can see.
Exercise
Your CI job runs npx commitlint --from origin/main --to HEAD and fails with an unknown revision error, although the commits are fine. Give a likely cause and a fix.
Show answer
The CI checkout is probably a shallow clone that does not include origin/main. Fetch the full history for that job (for example, set fetch-depth: 0 in GitHub Actions) or fetch the base branch explicitly before running commitlint.