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}
@pit-crew
Copy link

pit-crew commented Dec 5, 2019

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

@alasdairhurst
Copy link

alasdairhurst commented Dec 6, 2019

git tag sorts alphabetically. If you tags are versions, if you release 1, 2, 3 up to 11 in order, your list will be 1, 11, 2, 3, .... and not the expected order.

image

@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