tags:

views:

674

answers:

3

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?

+9  A: 

You could take a look at git describe, which does something close to what you're asking.

JB
With `--abbrev=0` it should return closest **annotated** tag
Jakub Narębski
A: 

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).

Greg Hewgill
A: 

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.

Wincent Colaiuta