Git log between tags

An expansion on the answers from @Yurii and @wilmol for those interested in generating a release notes file and wanting a script that is readable and easily modified.

export VERSION=$(git tag --sort=-committerdate | head -1)
export PREVIOUS_VERSION=$(git tag --sort=-committerdate | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}')
export CHANGES=$(git log --pretty="- %s" $VERSION...$PREVIOUS_VERSION)
printf "# 🎁 Release notes (\`$VERSION\`)\n\n## Changes\n$CHANGES\n\n## Metadata\n\`\`\`\nThis version -------- $VERSION\nPrevious version ---- $PREVIOUS_VERSION\nTotal commits ------- $(echo "$CHANGES" | wc -l)\n\`\`\`\n" > release_notes.md

The above script generates a markdown file at release_notes.md that looks like this:


🎁 Release notes (14.2)

Changes

  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP
  • ABCDEFGHIJKLMNOP

Metadata

This version -------- 14.2
Previous version ---- 14.1
Total commits ------- 5

I like this approach for a few reasons:

  • If there is a tag between the two tags I'm interested in, I can manually set $VERSION and $PREVIOUS_VERSION before running the last two lines.

  • With a few tweaks, I can sort, filter, and modify $CHANGES to meet my specific needs.


You need an ellipsis to indicate a range. Try git log tag1..tag2.

Tags:

Git