From fe488bfb099b86af3c471c42f682f0cef6962453 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 11 Feb 2015 11:21:27 +0100 Subject: [PATCH] how to show the latest git tag Signed-off-by: Nico Schottelius --- blog/how-to-show-the-latest-git-tag.mdwn | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 blog/how-to-show-the-latest-git-tag.mdwn diff --git a/blog/how-to-show-the-latest-git-tag.mdwn b/blog/how-to-show-the-latest-git-tag.mdwn new file mode 100644 index 00000000..bc115d7f --- /dev/null +++ b/blog/how-to-show-the-latest-git-tag.mdwn @@ -0,0 +1,44 @@ +[[!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]]