2

In git, let's say I have multiple tags with revision numbers, something like:

v1.1.0
v1.2.0
v1.2.1
v1.2.3

I'm interested in getting the last version number from the tag. If I do

git describe --tags --match "v1.2.*"

I will get v1.2.0 as the result, but I really want v1.2.3

Alex
  • 9,250
  • 11
  • 70
  • 81
  • `git describe` is used to find a tag that is reachable from HEAD. It sounds more like you just want to list out the tags and then sort them perhaps? – Andrew C Nov 14 '14 at 00:13

2 Answers2

1

If you want to list all tags, using a specifc order, you can (with git 2.0+) use a sort option.
See "How to sort git tags?"

git tag -l --sort=refname "v1.2.*"
# or (note the '-' sign in '-version' to reverse the order)
git tag -l --sort=-version:refname "v1.2.*"  

In each case, the first result should be v1.2.3

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I want just one tag, and git 2.0 isn't officially supported on Windows yet, which is the platform I need this for – Alex Nov 14 '14 at 15:00
  • @Alex to get one tag, you can use `head` (from https://github.com/bmatzelle/gow). But using on windows is indeed an issue (no Git2.x released yet in the new http://git-for-windows.github.io/ that I mentioned in http://stackoverflow.com/a/3144417/6309, although it's coming soon: http://osdir.com/ml/msysgit/2014-11/msg00015.html) – VonC Nov 14 '14 at 15:03
0

Also possible with git describe:

git describe --tags --match "v1.2.*" $(git rev-list --tags --max-count=1)

Helped this: https://stackoverflow.com/a/30811684/3598880

barbariania
  • 499
  • 8
  • 19