www.nico.schottelius.org/blog/how-to-show-the-latest-git-tag.mdwn
Nico Schottelius 374aad714e add correct indention
Signed-off-by: Nico Schottelius <nico@freiheit.schottelius.org>
2015-02-11 11:42:44 +01:00

44 lines
1.2 KiB
Markdown

[[!meta title="How to show the latest git tag"]]
## TL;DR
If you want to show the name of the latest tag, use:
git for-each-ref --sort=-taggerdate --count=1 --format '%(tag)' refs/tags
## Some background
The command *git for-each-ref* is pretty useful if you want to find something
in a number of commits (or tags in this case). It allows you to use variations of
output and sorting methods. For example:
### Show all tags including the message
git for-each-ref --format '%(refname) %(contents:subject)' refs/tags
(this is btw. very similar to **git tag -n1**)
### Show all tags sorted by date, oldest first
git for-each-ref --sort=taggerdate --format '%(refname)' refs/tags
### Show all tags sorted by date, newest first
git for-each-ref --sort=-taggerdate --format '%(refname)' refs/tags
### Show latest two tags
git for-each-ref --count=2 --sort=-taggerdate --format '%(refname)' refs/tags
### Show latest tag with its non-ambiguous short name
git for-each-ref --sort=-taggerdate --count=1 --format '%(refname:short)' refs/tags
### Show latest tag
git for-each-ref --count=1 --sort=-taggerdate --format '%(tag)' refs/tags
(note: this is the same as the previous one, but uses the *tag* field)
[[!tag git ungleich]]