Conventional commits that actually help
1 min read
On this page
fix stuff, wip, final final v2. We've all written them. Six months later they tell you nothing.
Conventional Commits is a tiny format that makes every commit say what kind of change it is.
The format
type(scope): what changed, in the imperative
Why it changed, if that isn't obvious. Wrap lines at 100 characters.The types you'll use most:
feat: something new for the user.fix: a bug fix.refactor: the code changed, the behaviour didn't.docs,style,test,build,ci,chore: everything around the code.
The scope is optional and names the area: feat(blog): add category tabs.
Why bother
A history like this reads like release notes:
feat(blog): add category tabs and an RSS feed
fix(about): keep the portrait card from stretching
refactor(motion): animate the comet with GSAPYou can see what changed without opening a single diff, generate a changelog from it, and spot a
feat hiding in a commit that was supposed to be a fix.
Make the machine check it
Nobody remembers a format under pressure, so let a hook do it. commitlint checks the message, and Husky runs it before every commit:
export default { extends: ["@commitlint/config-conventional"] };pnpm exec commitlint --edit "$1"A message that doesn't follow the format is rejected with a reason, like a body line that's too long, and you fix it before it lands.
Small commits, clear messages
The format works best when each commit does one thing. If the message needs "and", it's probably two commits.
- Git
- Husky
- commitlint
