Sub topic 12
Generating changelogs and releases from history
This chapter assumes you can write conventional commits, know how types map to MAJOR, MINOR, and PATCH, and can run shell commands. Here you will see how tools read that history to produce a changelog and a version number.
Why structured history is machine-readable
A tool cannot judge whether "tweaked the loader" was a feature or a bug fix. A tool can match feat: or fix:. The type prefix, the ! marker, and the BREAKING CHANGE footer give a program everything it needs to pick a version bump and group entries by kind.
The usual pipeline looks like this:
Computing the bump by hand
The core idea fits in a short script. It finds the latest tag, reads the commits after it, and applies the rules from the Semantic Versioning chapter.
#!/bin/sh
# Prints major, minor, patch, or none, based on commits since the last tag.
last_tag=$(git describe --tags --abbrev=0) || exit 1
range="$last_tag..HEAD"
if git log "$range" --format=%B | grep -Eq '^BREAKING[ -]CHANGE:|^[a-z]+(\([^)]*\))?!:'; then
echo major
elif git log "$range" --format=%s | grep -Eq '^feat(\([^)]*\))?:'; then
echo minor
elif git log "$range" --format=%s | grep -Eq '^fix(\([^)]*\))?:'; then
echo patch
else
echo none
fiThe checks run from highest to lowest because the largest change wins. One breaking commit among fifty fixes still means a major bump. Real tools do the same thing with a proper parser instead of grep.
You can also draft a changelog section with plain git log:
git log v1.2.0..HEAD --no-merges --format='- %s (%h)' --grep='^feat'
git log v1.2.0..HEAD --no-merges --format='- %s (%h)' --grep='^fix'Each command prints one group. Paste the groups under headings such as "Features" and "Bug fixes" and you have a changelog entry.
Tools that do this for you
| Tool | Approach |
|---|---|
| semantic-release | Runs in CI on every push to a release branch. It decides the version, tags, publishes, and writes release notes with no human step. |
| release-please | Opens and updates a "release pull request" containing the version bump and changelog. Merging that pull request creates the release. |
| conventional-changelog | Generates changelog files from commits. It leaves tagging and publishing to you. |
| git-cliff | A configurable changelog generator that supports conventional commits through templates. |
The choice is mostly about control. Fully automatic tools remove manual steps but publish whenever qualifying commits land. A release pull request adds a review point where you can read the notes before they ship.
What ends up in the changelog
Tools usually include feat, fix, and breaking changes, and often perf and revert. Types such as docs, style, test, and chore are commonly hidden by default. Most tools let you change this in configuration. The description line becomes the changelog bullet, so the description is user-facing text. "fix: prevent crash when the config file is empty" reads well in release notes. "fix: stuff" does not.
Failure modes to expect
- No previous tag.
git describefails in a repository with no tags. Release tools need a starting point, so create an initial tag first. - Wrong type, wrong version. A new feature committed as
fix:ships as a patch. Linting the format cannot catch a wrong choice of type, so review it in the pull request. - Hidden breaking changes. A breaking change without
!or the footer produces only a minor or patch bump. Consumers find out when their build breaks. - Rewritten history. Rebasing or amending after a tag exists can change the commit range a tool sees, so release from commits that are already merged and stable.
Exercise
Since tag v2.3.1, the history contains three commits: "fix(cli): handle empty input", "feat(api): add pagination", and "refactor(db)!: rename the users table". Which version will a conventional-commits release tool choose, and why?
Show answer
v3.0.0. The "!" in the refactor commit marks a breaking change, and the highest bump among the commits wins. The breaking change outweighs the feature (minor) and the fix (patch), so the major version increases and the others reset to zero.
Exercise
Your team squash-merges every pull request, but features are missing from the generated changelog. What is the first thing to check?
Show answer
Check the pull request titles, or whatever text the squash commit message uses. The release tool reads only the squashed commit on the main branch. If that message lacks a valid type such as "feat:", the tool cannot classify the change and leaves it out.