Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
170 views
in Technique[技术] by (71.8m points)

How to print git tag info selectively?

I need a way to print git tag info selectively.

Firstly I choose git for-each-ref to print all tag info:

git for-each-ref --format="%(refname:short)" refs/tags/

It's output looks like:

proj1_v1.0.0
    content
proj1_v1.0.1
    content
proj2_v1.0.0
    content

It's right, but I want to print the message which only contains "proj1".

After I find the solution in git dev guide(https://git-scm.com/docs/git-for-each-ref)

Used as %(if)…?%(then)…?%(end) or %(if)…?%(then)…?%(else)…?%(end). If there is an atom with value or string literal after the %(if) then everything after the %(then) is printed, else if the %(else) atom is used, then everything after %(else) is printed. We ignore space when evaluating the string before %(then), this is useful when we use the %(HEAD) atom which prints either "*" or " " and we want to apply the if condition only on the HEAD ref. Append ":equals=" or ":notequals=" to compare the value between the %(if:…?) and %(then) atoms with the given string.

I change my script to

 git for-each-ref  --format="%(if) %(refname:equals=proj1*)%(refname:short) %(end)" refs/tags/

But it raise error:

fatal: unrecognized %(refname:equals=hi) argument: equals=hi

Do I have a misleading on this sequence?

Append :equals=<string> or :notequals=<string> to compare the value between the %(if:…?) and %(then) atoms with the given string

question from:https://stackoverflow.com/questions/65641647/how-to-print-git-tag-info-selectively

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
git for-each-ref --format="%(if) %(refname)%(refname:short) %(end)" refs/tags/proj2*

is works.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...