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
617 views
in Technique[技术] by (71.8m points)

git - list tags contained by a branch

How can I list tags contained by a given branch, the opposite of:

git tag --contains <commit>

Which "only list tags which contain the specified commit".

If something like this does not exist, how do I test whether a commit is contained by another commit so that I can script this?

I could do this:

commit=$(git rev-parse $branch)
for tag in $(git tag)
do
    git log --pretty=%H $tag | grep -q -E "^$commit$"
done

But I hope there is a better way as this might take a long time in a repository with many tags and commits.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)
git tag --merged <branch>

From the man page:

--[no-]merged <commit>

Only list tags whose tips are reachable, or not reachable if --no-merged is used, from the specified commit (HEAD if not specified).

I believe this option was added quite recently - it definitely wasn't available back when the original question was posed and the above answers suggested. Since this thread is still the first hit in Google for the question I figured I'd throw it in for anyone who scrolls down to the bottom looking for an answer that involves less typing than the accepted answer (and for my own reference when I forget this answer again next week).


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

...