How to extract fixed issues in Git

Reginald LynchAugust 8th 2020, 5:00

A common use case of creating a release is to create a release note, containing, among other things, the bugs fixed in the release. A good practice is to write in the commit message whether a bug is fixed by the commit. A better practice is to have a standard way of doing this—for example, a line with the string "Fixes-bug: ", followed by the bug identifier in the last part of the commit message. This makes it easy to compile a list of bugs fixed for a release note. The JGit project is a good example of this; their bug identifier in the commit messages is a simple "Bug: " string followed by the bug ID.

Step 1 : Clone the JGit repository using the following command lines:

git clone
cd jgit 

Step 2 : If you want the exact same output as in this example, reset your master branch to d35f0ffb7c33a11f8192ec64da5a736827ab472d

git checkout master && git reset --hard d35f0ff

Step 3 : First, let's limit the log to only look through the history since the last tag (release). To find the last tag, we can use git describe:

git describe

The preceding output tells us three things:

  • The last tag was : v5.8.1.202007141445-r
  • The number of commits since the tag was 29
  • The current commit in abbreviated form is gd35f0ffb7

Step 4 : Now, let's say we want the release note format to look like the following template:

Commit-id: Commit subject 
Fixes-bug: ... 

Our command line so far is as follows:

git log --grep "Bug: " v5.8.1.202007141445-r..HEAD

Step 5 : This gives us all the bug fix commits, but we can format this to a format that is easily parsed with the --pretty option.

First, we will print the abbreviated commit ID (%h), followed by a separator of our choice (|), and then the commit subject (%s, the first line of the commit message), followed by a new line (%n), and the body (%b):


we just want the lines that contain "|" or "Bug: ":

grep -E "\||Bug: "

Then, we replace these with sed:

sed -e 's/|/: /' -e 's/Bug:/Fixes-bug:/'

The entire command put together is as follows:

git log --grep "Bug: " v5.8.1.202007141445-r..HEAD --pretty="%h|%s%n%b" | grep -E "\||Bug: " | sed -e 's/|/: /' -e 's/Bug:/Fixes-bug:/'

Step 6 : If we just wanted to extract the bug IDs from the commit messages and didn't care about the commit IDs, we could have just used grep after the git log command, still limiting the log to the last tag

git log  v5.8.1.202007141445-r..HEAD | grep "Bug: "

Step 7 : If we just want the commit IDs and their subjects, but not the actual bug IDs, we can use the --oneline feature of git log combined with the --grep option:

git log --grep "Bug: " --oneline  v5.8.1.202007141445-r..HEAD

Step 8 : Now, we can extract the bug information from the bug tracker and put the preceding code in the release note as well