<< back to the blog

Create a Changelog from `git log`

On a regular basis, you may want to tag the master branch with a (beta) version that is deployed to a customer's staging system.

People not engaged in development themselves (e.g. product owners) usually have a hard time following the changes that are made available with each new version. So the easiest way to help them is to create a readable changelog from the git log.

How we do it

We use GitLab, which requires us to work with so called "feature branches" and merge requests. Merge requests from the feature branches are usually merged into the master with a merge commit. This merge commit carries some of the description from the merge request, especially its subject.

In the end, the git log looks like the following: 

git log

The interesting parts here are the merge commits (denoted by the description starting with "Merge branch"). Those carry just enough information to create a changelog from them:

merge commit description

As you can see, we prefix the short description of the merge request with a tracker number from our ticketing system. 'CHGLOG' is the short title of the project and '556' is the ticket number within the system.

To create a changelog from this information from within the git repository, nothing more than the following bash script is needed:

project_upper=`echo $project | awk '{print toupper($0)}'`

TAG_STEP=`git tag -l --sort=creatordate|tail -2|sed 'N;s/\n/../'`
echo Changes in $project between $TAG_STEP:
git fetch origin -t 2>&1 > /dev/null
git log "${TAG_STEP}"|grep -E "    ${projects_match}-"|sed 's/   /*/'


This script outputs the following, which can be given to the product owner as soon as the next version has been deployed:

$ bash create_changelog.sh 
Changes in chglog between v0.1..v0.2:
* CHGLOG-556: Make bullet points list
* CHGLOG-456: Improvements to the Changelog
* CHGLOG-123: Basic Changelog implementation


<< back to the blog