Post

Git pull list of commit messages since last tag

Git pull list of commit messages since last tag

Git pull list of commit messages since last tag

When preparing release notes, I need all the commit messages since the last tagged release. The git describe --tags trick gets the most recent tag automatically, so I don’t have to hardcode it. The grep filtering removes merge commits and the sort | uniq cleans up any duplicates from cherry-picks.

Get the last tag name

1
$ git describe --tags --abbrev=0

Now get all changes from last tag till now

1
$ git log $(git describe --tags --abbrev=0)..HEAD

Extract information using grep

Now grep all commit messages that have JIRA mentioned in them

1
$ git log $(git describe --tags --abbrev=0)..HEAD |grep "JIRA"

Now remove all merge request information

1
$ git log $(git describe --tags --abbrev=0)..HEAD |grep "JIRA" | grep -v "\bCloses\W\|\bMerge branch\W\|\borigin/CISR\|\bResolve\W"

Now sort the commit messages and return only unique records

1
$ git log $(git describe --tags --abbrev=0)..HEAD |grep "JIRA" | grep -v "\bCloses\W\|\bMerge branch\W\|\borigin/CISR\|\bResolve\W" | sort| uniq

Extract information using awk

Use awk to find all commit messages that start with word JIRA

1
$ git log $(git describe --tags --abbrev=0)..HEAD | awk '$1 ~ /^JIRA/'

Now sort the commit messages and return only unique records

1
$ git log $(git describe --tags --abbrev=0)..HEAD | awk '$1 ~ /^JIRA/' | sort | uniq

Extract information by simply using git parameters

1
$ git log --no-merges --oneline --format=%s $(git describe --tags --abbrev=0)..HEAD 
  • –no-merges : remove all merge information
  • –oneline : remove date and author information
  • –format=%s : %s is to return the commit message and removing the commit hash information

Now sort the commit messages and return only unique records

1
$ git log --no-merges --oneline --format=%s $(git describe --tags --abbrev=0)..HEAD | sort | uniq
This post is licensed under CC BY 4.0 by the author.