I have a repository in which a lot of tags. I would like to see only the last few. If I use a regular command, I get a complete list of tags, and it is sorted in the reverse order of the one I need.

git tag v1.0.0 v1.1.0 v2.0.0 v2.0.0RC1 v2.0.0RC2 v2.0.0RC3 v2.0.1 v2.1.0 v2.1.0RC1 v2.1.0RC2 

What I want:

 git magic v2.1.0RC2 v2.1.0RC1 v2.1.0 

How can I get a list of N recent tags, sorted in the order I need?


For future tagging related questions in different languages: https://stackoverflow.com/questions/30805098/how-to-display-last-n-tags-in-git

    1 answer 1

    Using git tag --sort (Git v 2.0.0+)

    Note that I use the minus sign - to invert the sort order (the default is from older to newer).

    UNIX, Linux, OS X: head utility

     git tag --sort=-version:refname | head -n <number> 

    Windows UNIX way

    1. Install Cygwin
    2. Use answer for UNIX

    Windows command Select

     git tag --sort=-version:refname | Select -First <number> 

    Using git describe

     git describe --tags $(git rev-list --tags --max-count=<number>) 

    ( This is a translation of your own answer . A variant with describe is suggested by @hsirah .)