Generating a changelog based on merge commits

Here’s a useful command that I’ve been using for a while. It generates a changelog, based on all merge commits since the latest release was tagged.

git log $(git describe --abbrev=0 --tags).. \
--merges --pretty=format:"%b" \
| grep -E '^[A-Z]+\-[0-9]+'

If we break this down, we get to the following:

git describe --abbrev=0 --tags

This will give you the latest tag name, eg: 1.24.3. This value will be parsed in the git log command, as follows:

git log 1.24.3.. \
--merges --pretty=format:"%b" \
| grep -E '^[A-Z]+\-[0-9]+'

The flag --merges makes sure that only merge commits are included.--pretty-format:"%b" will limit the output from git log to only include the body of the merge commit. So given the following merge commit:

commit 5e15780ffad8ba4838e84916f64a2bbbf785f19b
Merge: db6e41a f1607b8
Author: Anse <john@doe.com>
Date: Tue Mar 27 15:08:07 2018 +0200
Merge pull request #1005 from xxx/feature/TICKET-3036
TICKET-3036: Ticket description goes here

It woud output: TICKET-3036: Ticket description goes here

After that we’ll narrow down the output to only include lines that start with a ticket number, using grep -E '^[A-Z]+\-[0–9]+'

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.