Commit conventions
Last updated
Many teams add a small rule on top of lesson 1.7: start every message with its kind of change, like "fix:" or "feat:". That's Conventional Commits. Because the messages follow a pattern, tools can read them, building a changelog and choosing the next version number by themselves. In this lesson you'll write messages in that form, and meet sign-offs.
By the end of this lesson you can
- Write commit messages that follow Conventional Commits 1.0.0
- Explain how tools use those messages for changelogs and version numbers
- Say what a Signed-off-by line and the Developer Certificate of Origin are
The form
A Conventional Commits subject is:
type(scope): description fix(adobo): use 1 tsp salt, not 1 tbsp feat: add pancit palabok recipe docs(readme): explain how to build the index
- type says what kind of change it is. The specification defines feat (a new feature) and fix (a bug fix); teams commonly add docs, refactor, test, build, ci, chore, style, perf and revert.
- (scope) is optional: which part of the project.
- description is a short summary, usually lower-case after the colon, with no full stop.
- A change that breaks something people relied on adds
!before the colon (feat!: rename every recipe file), or a footer lineBREAKING CHANGE: links to recipes have changed.
Everything from lesson 1.7 still applies: short, specific, and saying what changed. Some teams also keep lesson 1.7's capital letter and command form after the colon; follow your team.
Rewrite five messages
The message:
Fixed the flanWhat the commit did: Changed leche-flan.md from 10 egg yolks to 12, which was a mistake in typing it up.
0/72The message:
palabok!!What the commit did: Added a new recipe file, pancit-palabok.md.
0/72The message:
readmeWhat the commit did: Explained in README.md how to run the index script.
0/72The message:
cleanupWhat the commit did: Tidied build_index.py so it reads better. What it makes is exactly the same.
0/72The message:
Rename everythingWhat the commit did: Moved every recipe into a folder per course (mains/, desserts/), which breaks old links to them.
0/72
Changelogs and versions, made for you
Because every message says its type, a tool can read the history since the last tag and:
- write a changelog: features under "Features", fixes under "Bug Fixes", breaking changes at the top;
- choose the next version (lesson 3.6): any breaking change → MAJOR; else any feat → MINOR; else fix → PATCH.
## 2.0.0 ### ⚠ BREAKING CHANGES * move recipes into a folder per course ### Features * add pancit palabok recipe ### Bug Fixes * **flan:** use 12 egg yolks
Release tools such as release-please and semantic-release do this; Simple Software Development 7.4 covers releases.
Commit with the team’s hook
The family has installed a commit-msg hook (lesson 7.3) that refuses messages not in this form.
- Change a recipe, and try committing with a message like “Fix the adobo”. Read what the hook says
- Commit it again in Conventional Commits form
- Add a new recipe file as a
feat
Working folder
no changes
Staging area
nothing staged
Repository
10 commits on main
You are in ~/kusina. The family has agreed on Conventional Commits, and a commit-msg hook checks every new message.
Sign-offs and the DCO
Some projects (the Linux kernel, Git itself, and many others) ask for a line at the end of each message:
fix(adobo): use 1 tsp salt Signed-off-by: Ana Reyes <[email protected]>
git commit -s adds it, from your configured name and email. In those projects it means you agree to the Developer Certificate of Origin: a short statement that you wrote the change, or otherwise have the right to submit it under the project's licence. It isn't a signature in the cryptographic sense (lesson 7.4 has signed commits). Only add it where a project asks for it, and read the DCO first.
Spot the trap: feat: stuff
Joaquin learns the convention, and his next commit is feat: stuff.
What happens if…
Check what you learned
Sources
Every command on this page behaves as these pages describe, and the sandbox prints what Git 2.55 prints. Hosting features (pull requests, protected branches) come from the host’s own documentation.
- Conventional Commits 1.0.0: the specification, and how it maps to semantic versioning
- Developer Certificate of Origin: what a sign-off certifies
- Git documentation: git-commit, --signoff: adding the trailer, and what it means depends on the project