What's the simplest way to get the most recent tag in Git?
git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag
output:
a
b
c
Should I write a script to get each tag's datetime and compare them?
What's the simplest way to get the most recent tag in Git?
git tag a HEAD
git tag b HEAD^^
git tag c HEAD^
git tag
output:
a
b
c
Should I write a script to get each tag's datetime and compare them?
You could take a look at git describe
, which does something close to what you're asking.
My first thought is you could use git rev-list HEAD
, which lists all the revs in reverse chronological order, in combination with git tag --contains
. When you find a ref where git tag --contains
produces a nonempty list, you have found the most recent tag(s).
How about this?
TAG=$(git describe $(git rev-list --tags --max-count=1))
Technically, won't necessarily get you the latest tag, but the latest commit which is tagged, which may or may not be the thing you're looking for.