Fredrik
Fredrik

Reputation: 5108

Display most recent release (v*) tag(s)

What I want

A way to see the most recent release tag(s).

What I've tried

I went down a short path on git describe but I couldn't find how to make it work on all refs (get tags from all branches). I also briefly looked at show-refs, for-each-ref & rev-list but couldn't quite get it to do what I wanted.

Currently I use this to list out all tags starting on v and sort them in descending order, based on refname:

git tag -l v* --sort=-v:refname

which gives an output looking like

v2.0.32
v2.0.31
v2.0.29
v2.0.28
v2.0.27
v2.0.26
v2.0.25
v2.0.24
v2.0.23
v2.0.22
v2.0.21
v2.0.20
v2.0.19
v2.0.18
...

which is all good, except it's too much. I'd like to use some of limiter argument but I can't seem to find anything to limit the output.

Upvotes: 1

Views: 66

Answers (1)

Fredrik
Fredrik

Reputation: 5108

Solution

So I found the solution while writing this question:

git tag -l 'v*' --sort=-v:refname | sed -n 1,5p

The piped sed command will print only lines 1 through 5. I had this aliased under git v as git config alias "tag -l 'v*' --sort=-v:refname | sed -n 1,5p" which has be changed to

git config alias.v "! git tag -l 'v*' --sort=-v:refname | sed -n 1,5p"

Note the ! in front, which tells git to interpret it as an external command (which is why we also add the git, which you usually don't start your git aliases with) which allows us to pipe stuff, instead of doing just doing git commands.


Edit, from @LeGEC in the comments below: Instead of sed -n 1,5p you can use

head -5

to specify the range, which is arguably more intuitive.

Upvotes: 2

Related Questions