This can be done using the git tag --sort , which is introduced in Git v 2.0.0.
Note. I use the minus sign - to get the reverse sort order (the oldest and newest by default).
Replace <number> with the actual natural number.
UNIX, Linux, OS X
git tag --sort=-version:refname | head -n <number>
From man head :
head [-n count | -c bytes] [file ...]
This filter displays the first count lines or bytes of each of the specified files or standard input if no files are specified. If the counter is omitted, it defaults to 10.
Windows UNIX path
- Install Cygwin
- See answer for UNIX
Windows native way
git tag --sort=-version:refname | Select -First <number>
(Information about the Select command was found on serverfault )
--sort=<type>
Sort in a specific order. The supported type is "refname" (lexicographic order), "version: refname" or "v: refname" (tag names are treated as versions). The sorting order of "version: refname" can also be affected by the configuration variable "versionort.prereleaseSuffix". Prepare a “-” to reverse the sort order. If this option is not specified, the default sort order corresponds to the value configured for the tag.sort variable, if one exists, or the lexicographic order otherwise.
source share