Git tags based on a pattern

Viewed 636

There are different versions of tags in our repository. Need to get a particular patterned tag only assuming there's only one occurrence of that type. E.g

v1.1.0
1.0
v1.0
v0.1.0-0.20201201002611-5424ca76ab3e
v1.2.0-alpha 

How can I get a particular which only follows v0.1.0-0.20201201002611-5424ca76ab3e

I have the regex v[0-9]*.[0-9]*.[0-9]-0.\d{14}-\b[0-9a-f]{12}\b

I tried it using git describe --match "v[0-9]*.[0-9]*.[0-9]-0.\d{14}-\b[0-9a-f]{12}\b" --abbrev=0 --tags $(git rev-list --tags) but doesn't seem to work. Any other way I could get the tag with a specific format?

1 Answers

You can use the following POSIX BRE pattern:

'v[0-9]*\(\.[0-9]*\)\{2\}-0\.[0-9]\{14\}-[0-9a-f]\{12\}'

where

  • v - matches v
  • [0-9]* - zero or more digits
  • \(\.[0-9]*\)\{2\} - two repetitions of . and zero or more digits
  • -0\. - a 0. string
  • [0-9]\{14\} - fourteen digits
  • - - a hyphen
  • [0-9a-f]\{12\} - twelve digits or lowercase letters.
Related