Automating Documentation from Git History
This lesson shows how commit messages become changelogs in a pipeline.
Learning outcomes
After completing this lesson, you will be able to:
- Write commit messages that follow Conventional Commits.
- Use git log to read a range of commits.
- Explain why fetch depth matters.
- Build a release workflow that creates notes from history.
Why history can become documentation
Each commit carries an author, a date and a message. If messages are consistent, a tool can read a range of commits and produce a changelog with no extra writing. If messages are vague, such as fix stuff, no tool can help. Generating documentation from history is therefore mostly about agreeing on a format, then enforcing it.
Conventional Commits
Conventional Commits is a widely used specification for commit messages. Each message has a type, an optional scope and a description, and may have a body and footers.
feat(checkout): add saved payment methods
Customers can now reuse a card that they saved earlier.
Refs: AB#2041
BREAKING CHANGE: the /v1/cards endpoint now requires a customer IDThe type drives the outcome. A fix corresponds to a semantic versioning patch, a feat to a minor version, and a BREAKING CHANGE footer or an exclamation mark after the type, such as feat!:, to a major version. Other types, such as docs, test, chore and ci, normally have no effect on the version.
A commit-message hook can check the format locally, and a pull request check can verify it in a pipeline. When a team uses squash merging, the pull request title becomes the commit message on main, so that title is what needs checking.
Which version part changes?
Commands for reading history
Git itself can produce the raw material. The following commands are useful in a pipeline.
# List commits between two tags, one line each
git log v2.2.0..v2.3.0 --oneline
# Print only commit subjects, with merge commits left out
git log v2.2.0..HEAD --no-merges --pretty=format:"- %s (%h)"
# Summarize commits by author
git shortlog -sn v2.2.0..v2.3.0
# Find the most recent tag reachable from HEAD
git describe --tags --abbrev=0The range A..B means commits reachable from B and not from A, which is exactly what has changed since a previous release. The --pretty=format option controls the output, with %s for the subject, %h for the short hash, %an for the author and %ad for the date.
Git commands for release notes
Automating in a pipeline
The following workflow runs when a version tag is pushed, and it creates a changelog from the commits since the previous tag. Note the fetch-depth: 0 setting. By default, actions/checkout performs a shallow clone with a depth of one, which contains neither older commits nor tags, so git log would have nothing to read. In Azure Pipelines, the equivalent is fetchDepth: 0 on the checkout step, and fetchTags: true if tags are needed.
name: release-notes
on:
push:
tags: ['v*']
permissions:
contents: write
jobs:
notes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build the changelog
run: |
PREVIOUS=$(git describe --tags --abbrev=0 HEAD^)
git log "$PREVIOUS"..HEAD --no-merges --pretty=format:"- %s (%h)" > notes.md
- name: Create the release
env:
GH_TOKEN: ${{ github.token }}
run: gh release create "$GITHUB_REF_NAME" --notes-file notes.mdThe contents: write permission is needed because creating a release writes to the repository. Dedicated tools such as semantic-release and release-please go further: they read Conventional Commits, calculate the next version, update a changelog file and create the tag, so that a release requires no manual step.
The following diagram compares a pipeline's shallow clone with the full history, which explains why git log printed only one commit.

Release notes in a workflow
An empty changelog
A pipeline step runs git log to build release notes, but the output contains only the most recent commit. The same command prints the full list on a developer's laptop. What is the most likely cause?
The pipeline uses a shallow clone, so it has only the latest commit. Setting fetchDepth: 0 in Azure Pipelines, or fetch-depth: 0 in GitHub Actions, provides the full history. The permissions of the pipeline identity do not limit which commits appear in a clone, and the format of commit messages would affect the text of the entries but not how many entries are listed.
A commit message begins feat!: remove the v1 endpoint. Which SemVer part should change?
Show answer
MAJOR. The exclamation mark marks a breaking change, whatever the type.
Exam Tips
Remember for the exam
- Consistent commit messages are the input for generated changelogs.
- feat is minor, fix is patch, and BREAKING CHANGE is major.
- git log A..B lists commits in B that are not in A.
- Shallow clones hide history; set fetch depth to 0.
- With squash merging, the pull request title becomes the commit message.