Skip to content

Instantly share code, notes, and snippets.

@developernotes
Created July 5, 2012 20:45
Show Gist options
  • Save developernotes/3056312 to your computer and use it in GitHub Desktop.
Save developernotes/3056312 to your computer and use it in GitHub Desktop.
Display a simple changelog between the last two tags in a Git repository
#! /usr/bin/env sh
firstTag=$(git tag | sort -r | head -1)
secondTag=$(git tag | sort -r | head -2 | awk '{split($0, tags, "\n")} END {print tags[1]}')
echo "Changes between ${secondTag} and ${firstTag}\n"
git log --pretty=format:' * %s' ${secondTag}..${firstTag}
@leosuncin
Copy link

Tags sorted by date:

firstTag=$(git tag --sort=-committerdate | head -1)
secondTag=$(git tag --sort=-committerdate | head -2 | tail -1)

@Aure77
Copy link

Aure77 commented Jan 25, 2021

Faster (only 1 git command) sorted by date:

latestTags=($(git for-each-ref refs/tags/* --sort=-taggerdate --count=2 --format="%(refname:short)"))
firstTagHF=${latestTags[0]}
secondTagHF=${latestTags[1]}

You can also filter by name if you want:
git for-each-ref refs/tags/<tag_name_start>*

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment