Git commit messages: format, examples and Conventional Commits
How to write good commit messages: Conventional Commits types (feat, fix, chore), a subject under 50 characters, a useful body, and ready-to-use examples.
You open git log on a two-year-old project and find this: "fix", "tweaks", "wip", "trying again", "final version 2". There's no way to know what changed, or why. When you need to understand why a function was rewritten three months ago, you're reading one diff at a time, guessing the intent of someone who's no longer on the team.
This post is the standard I use for commit messages: the subject and body format, the Conventional Commits types, ready-to-use examples, and how to enforce it all with commitlint. If you're still on the fundamentals (branches, staging, merge), start with Git for beginners.
Why commit messages matter
A commit isn't a save button. It's dated documentation, attached to exactly the change it explains. Three situations where a good message saves hours:
- Understanding a regression.
git bisectfinds the commit that introduced a bug based on test results (you mark each versiongoodorbad), not on the message. But when it stops and says "the culprit isa1b2c3", the message decides whether you understand what happened in ten seconds or in half an hour. "fix" says nothing;fix(auth): prevent infinite loop when the token expires in UTC-3gives you the context before you open the diff. - Generating changelogs and versions automatically. Tools like
semantic-releaseandconventional-changelogread the history to write release notes and decide the next version number. No structure, no automation. - Async review and
git blame. Whoever reviews the PR in another timezone, or lands on the code a year from now throughgit blame, reads the message before the code.
Anatomy of a good message: subject, blank line, body
The git commit documentation itself recommends starting the message with a single short line, no more than 50 characters, summarizing the change, followed by a blank line and a more thorough description. Tim Pope's classic guide from 2008 adds the other half of the rule: wrap the body at about 72 columns, because git log doesn't wrap lines and an 80-column terminal leaves 72 after a 4-column indent on each side.
The rule I follow, unified:
- Subject of up to 50 characters as the target, and 72 as the hard limit. Past 72,
git log --onelineoverflows and GitHub cuts the subject off with an ellipsis (observed behavior, not officially documented). - A blank line between subject and body. Git treats everything up to the first blank line as the title; without it,
git log --oneline,git rebase -i, and GitHub show subject and body glued together. - Body wrapped at 72 columns, explaining the why, not the how (the how is in the diff).
- Footer with references:
Refs: #1847,Closes #123(GitHub closes the issue when the commit reaches the default branch), orBREAKING CHANGE:.
fix(billing): round invoice total in cents
Floating-point math produced totals like 59.699999999999996 (three
items at 19.9), and bank reconciliation rejected the invoice. We now
sum in cents (integers) and convert only for display.
Didn't use toFixed(2) because it returns a string and rounds 1.005 to
"1.00", since 1.005 has no exact binary representation.
Closes #1847
A practical rule for whether you need a body: if someone in review would ask "why did you do it this way?", the answer goes in the body. The body doesn't show in git log --oneline, but it does in git show, the full git log, and the commit page on GitHub.
Conventional Commits: the most widely adopted commit standard
Conventional Commits is a specification (version 1.0.0) that gives the subject a minimal structure:
<type>(<optional scope>): <description>
<optional body>
<optional footer(s)>
It's widely adopted in JavaScript projects and product teams, but it isn't universal: the Linux kernel and Git itself use other conventions. Its value is the automation it enables.
Which types the specification defines (and where the others come from)
A detail almost every tutorial gets wrong: the specification defines only two types, and both affect semantic versioning:
feat: a new feature, corresponds to a MINOR release.fix: a bug fix, corresponds to a PATCH release.
The specification says other types are allowed and mentions the ones recommended by @commitlint/config-conventional, based on the Angular convention. Those have no implicit effect on SemVer. The full list commitlint accepts, checked against version 21.2.4 (November 2026):
| Type | When to use |
|---|---|
feat |
New feature |
fix |
Bug fix |
docs |
Documentation only |
style |
Formatting, whitespace, semicolons, no logic change |
refactor |
Internal change without behavior change |
perf |
Performance improvement |
test |
Adding or fixing tests |
build |
Build system and dependencies (npm, Vite, Dockerfile) |
ci |
CI configuration (GitHub Actions, pipelines) |
chore |
Maintenance that doesn't fit any of the above |
revert |
Reverts a previous commit |
Note that CI has its own type: updating a GitHub Actions workflow is ci, not chore. Examples:
feat(payments): add support for recurring Pix payments
fix(auth): fix token refresh when the session expires
build(deps): upgrade Node.js from 22 to 24 LTS
ci: run tests in parallel on GitHub Actions
refactor(user): extract CPF validation into a service
revert: undo "feat(payments): add support for recurring Pix payments"
Breaking changes and the major version
A change that breaks compatibility is flagged with ! right before the colon or with a BREAKING CHANGE: footer (uppercase; it's the only part the specification requires that way, and BREAKING-CHANGE is a synonym). It can appear on a commit of any type and corresponds to a MAJOR release.
feat(api)!: remove the /v1/users endpoint
BREAKING CHANGE: /v1/users was removed. Migrate to /v2/users as
described in docs/migration-v2.md.
That's what semantic-release uses to bump the major version automatically. I use both signals together: semantic-release's default preset (angular) documents detection through the BREAKING CHANGE footer, and the ! makes the break visible in git log --oneline. Under its default rules, feat produces a minor release, fix and perf a patch.
Scope: when it's worth it
The scope in feat(scope): is optional. It pays off in a monorepo or a backend with separate domains (checkout, inventory, auth), because it saves reading time. In a small project where everything is one module, it's noise.
Imperative mood, and teams that don't write in English
Git's contributor guidelines recommend describing the change in imperative mood ("make xyzzy do frotz"), as if you were giving orders to the codebase. In English that's natural: add email validation, fix race condition. It also matches the messages Git itself generates, like Merge branch 'feature/x' and Revert "...". A good test: the subject should complete the sentence "If applied, this commit will...".
What to avoid:
added email validation: past tense, narrates what you did instead of what the commit does.adding email validation: present continuous.email validation was added: passive voice, buries the verb at the end.
Teams writing in other languages don't always have a clean equivalent. In Portuguese, for example, teams split between the infinitive ("adicionar validação") and the third-person present ("adiciona validação"), and the official Portuguese translation of the specification mostly uses the third person. Whatever the language, pick one form for the whole team; consistency matters more than the form.
On language itself: if the team, the issues, and the documentation are in another language, writing commits in that language is fine; nobody gains anything from stilted English. If the project is open source or the team is international, use English. What doesn't work is mixing both in the same history.
Antipatterns that ruin history
- Diary commits:
monday,monday 2,today's work. A change history isn't a timesheet; it says what changed, not when you worked. - Giant commits: fifty files across five concerns. If you can't summarize the commit in 50 characters, it's probably too big; split it into pieces that make sense on their own.
- Permanent WIP:
wipis fine on your short-lived branch, not inmain's history. Before the PR, combine and rename withgit rebase -i(walkthrough in git merge vs rebase) or let the PR's squash merge handle it. - Lying messages:
fix typothat refactors half a module. Bisect still finds the right commit, but anyone reading the message is led to skip exactly the commit that matters.
How to enforce the standard with commitlint and Husky
commitlint checks the message against a configuration. The part many tutorials get wrong: it runs in the commit-msg hook, which receives the file containing the message. The official guide states plainly that the pre-commit hook isn't supported (it runs before the message exists). And installing the packages doesn't wire anything up by itself; it takes three steps. I ran the sequence below in a test repository with Node 24, commitlint 21.2.4, and Husky 9.1.7:
npm install -D @commitlint/cli @commitlint/config-conventional husky
npx husky init
echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg
Then the configuration. Use the .mjs extension: the guide shows commitlint.config.js with export default, but current npm init creates package.json with "type": "commonjs", and in that case the .js file breaks with SyntaxError: Unexpected token 'export'.
// commitlint.config.mjs
export default {
extends: ['@commitlint/config-conventional'],
rules: { 'header-max-length': [2, 'always', 72] },
};
The extra rule is there because config-conventional's default subject limit is 100 characters, which is far too loose. Two caveats: husky init also creates a .husky/pre-commit that runs npm test; adjust or delete it if the project has no tests. And the conventional config rejects subjects that start with a capital letter ("sentence-case") or end with a period. In the test, messages behaved like this:
tweaks -> rejected: type-empty, subject-empty
Chore: Configure commitlint. -> rejected: type-case, type-enum, subject-case, subject-full-stop
ci: run commitlint in pipeline -> accepted
feat(api)!: remove endpoint ... -> accepted (with a BREAKING CHANGE footer)
For CI, the official guide validates a PR's commits with npx commitlint --from <base sha> --to <head sha> --verbose. It's also worth knowing Commitizen, a CLI that asks for type, scope, and description and builds the message for you, handy while the team is still memorizing the format.
Frequently asked questions
Do I need Conventional Commits on a personal project?
No. The direct benefit (automatic changelog and versioning) only shows up once the tooling is configured. But the cheap part is always worth it: short descriptive subject, blank line, body with the why. You yourself, three months from now, will be grateful for fix(parser): accept dates in DD/MM format instead of fix.
What's the ideal commit message length?
A subject of up to 50 characters as the target and 72 as the ceiling; a body wrapped at 72 columns, as long as the explanation needs. Most commits don't need a body; the ones that change behavior, fix a subtle bug, or make a non-obvious decision do.
How do I fix the last commit message?
git commit --amend -m "new message" rewrites the last commit. If it hasn't been pushed yet, go ahead. If it has, you're rewriting published history and will need a force push; on a shared branch, prefer leaving it alone. Older commit messages are fixed with git rebase -i and reword, and the other ways of going back are in how to undo changes in Git.
How do I adopt the standard on a team without friction?
Start with CI: validate the PR's commits with commitlint and surface the error in review, without blocking local commits. Once the team is used to it, turn on the commit-msg hook with Husky. Introduce the convention through review first and automate later; blocking everyone's commits on day one is the shortest path to someone running git commit --no-verify forever. If the team is also settling its branching flow, see Git branching strategies.
Write for whoever reads the history a year from now
Short imperative subject, blank line, body with the why, a Conventional Commits type up front when the project automates versioning. Remember the specification only defines feat and fix; the rest is commitlint convention, and BREAKING CHANGE is what bumps the major. Enforce the standard in the right hook (commit-msg), start with CI, and pick one style for the whole team. With an organized history, generating the changelog and documenting the project comes almost for free, as I show in documenting projects on GitHub.
The editorial content ends here. When I want to check whether a commit message matches what changed in a file outside the repository, like a production config before and after, I paste both versions into the Quick Tools Text Diff Checker and see the differences side by side.
- 01 CPU Cores vs. Threads: What Actually Changes in Practice Understand the difference between CPU cores and threads and what actually changes for performance, multitasking, gaming, and development.
- 02 MIT, Apache, and GPL Licenses: Practical Differences for Developers MIT, Apache 2.0, and GPL are not the same thing. Understand permissive vs copyleft, patent protection, and compatibility before shipping code to production.