Is it possible with Git to retrieve a list of tags that exist only in a certain branch?

让人想犯罪 __ 提交于 2019-11-30 08:41:49

问题


I would like to know if it's possible in Git to retrieve a list of tags (much like the result of the git tag command), but the list should be limited only to a certain branch.

If this is possible, can anyone explain how this is done? Perhaps with some pattern-matching magic?


回答1:


Another approach would be possible with the new git tag options --merged (in git 2.7+, Q4 2015)

git tag --merged <abranchname>

See commit 5242860, ... (10 Sept 2015) by Karthik Nayak (KarthikNayak).
(Merged by Junio C Hamano -- gitster -- in commit 8a54523, 05 Oct 2015)

tag.c: implement '--merged' and '--no-merged' options

Use 'ref-filter' APIs to implement the '--merged' and '--no-merged' options into 'tag.c'.

  • The '--merged' option lets the user to only list tags merged into the named commit.
  • The '--no-merged' option lets the user to only list tags not merged into the named commit.

If no object is provided it assumes HEAD as the object.




回答2:


I think this will do what you want:

 git log --pretty='%H' <branch> |
   xargs -n1 git describe --tags --exact-match 2>/dev/null

This uses git log to get a list of commits in a branch, and then passes them to git describe to see if they correspond to a tag.



来源:https://stackoverflow.com/questions/10602780/is-it-possible-with-git-to-retrieve-a-list-of-tags-that-exist-only-in-a-certain

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!