Yuchen
Yuchen

Reputation: 33036

How to list git tags with certain format or filter

We would like to encode our build version number in git tags. For example, we will have git tags like this:

release/3.4.4/7889 
release/3.4.5/7890
release/3.4.5/7891
...

We know that simply calling git tag will give a list of git tags in the history. Is there a way to tell git to only return some tags following certain formate? For example, is that a way to find all git tags starting with release/3.4.4/?

Upvotes: 6

Views: 3582

Answers (1)

larsks
larsks

Reputation: 311615

For example, is that a way to find all git tags starting with release/3.4.4/?

If you read through the git tag documentation, you find:

git tag [-n[<num>]] -l [--contains <commit>] [--no-contains <commit>]
  [--points-at <object>] [--column[=<options>] | --no-column]
  [--create-reflog] [--sort=<key>] [--format=<format>]
  [--[no-]merged [<commit>]] [<pattern>...]

So, you can simply run:

git tag -l release/3.4.4/*

You may want to escape that * to avoid erroneous wildcard expansion in the shell:

git tag -l release/3.4.4/\*

Upvotes: 6

Related Questions