How to get the branch from tag name in Git?

泄露秘密 提交于 2020-02-04 01:29:33

问题


I am trying to get the branch name from a given tag. I tried git describe --tag <tag-name> but this doesn't provide me any branch name. I tried using gitk to show to the tags and branch but gitk doesn't show me the tag. When I list out the tags git tag -l I see the tag name exist in the list.

I just want a simple command which can tell me the branch when tag name is provided.


回答1:


Tags and Branches in Git are only Labels pointing to specific snapshot of your files. That being said, Tags ain't linked to a branch, but to a commit.

As so, you have to check wich branch contain the commit pointed by your tag, as so:

git branch --contains <tag name>



回答2:


A tag is just an alias name for a commit.

That said, this should answer your question: https://stackoverflow.com/a/2707110/550177




回答3:


If you know the commit number the tag is linked to, you can find the branch from which the tag was placed from this command:

git_branch=$(git for-each-ref | grep ${commit_num} | grep origin | sed "s/.*\///")


来源:https://stackoverflow.com/questions/12754078/how-to-get-the-branch-from-tag-name-in-git

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