How can I get the latest tag of the form vX.X.X.X?

731 views Asked by At

Here is a list of tags I get when I do git describe --tags:

v1.1.8
v1.1.9
v1.2.0
v1.2.0.1
v1.2.0.10
v1.2.0.11
v1.2.0.12

If I do

git describe --tags `git rev-list --tags --max-count=1`

I may get tag with either 3 digit or 4 digit. I only want to pick up the latest 4 digit tag. How can I always get the latest 4 digit git tag?

What I mean by the 4 digit tag is anything with vX.X.X.X

1

There are 1 answers

0
jub0bs On BEST ANSWER

Edit: You write

I only want to pick up the latest 4-digit tag.

(my emphasis)

However, your question really only makes sense for annotated tags, which, contrary to lightweight tags, do have a date associated to them. In that respect, a lightweight tag is not that much different from a branch reference.

  • To list all tags (either annotated or lightweight) in your repository that match the pattern vX.X.X.X (where X stands for one or more digits), run

    git tag | grep -E "v([0-9]+\.){3}[0-9]+"
    

If you want something else, please clarify your question.