Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: How to find out on which branch a tag is?

Tags:

git

branch

tags

I'm currently busy with a project with a lot of branches and I have a tag for last changes which where done on one of the branches. But it's not clear for me on which branch this tag is.

How to find out on which branch a tag is?

like image 870
Viacheslav Kondratiuk Avatar asked Apr 04 '13 08:04

Viacheslav Kondratiuk


People also ask

How can I tell which branch a tag was made?

So when you are on a dev branch and Tag this state. Your tag is on the actual reference. So in this case you can look to gitk or another tool where the tree is shown. There you can see on which reference the Tag is.

Is a tag specific to a branch?

Tags and branch are completely unrelated, since tags refer to a specific commit, and branch is a moving reference to the last commit of a history. Branches go, tags stay. So when you tag a commit, git doesn't care which commit or branch is checked out, if you provide him the SHA1 of what you want to tag.

Are git tags across branches?

Yes! The difference between a branch name and a tag name is that a branch name is expected to move, and git will move it automatically in that "on a branch" case.


1 Answers

Even shorter:

git branch --contains tags/<tag> 

(it works for any tree-ish reference)


If you can find which commit a tag refers to:

 git rev-parse --verify tags/<tag>^{commit}  # or, shorter:  git rev-parse tags/<tag>~0 

Then you can find which branch contain that commit.

git branch --contains <commit> 

As commented below by user3356885, for the fetched branches (branches in remotes namespace)

git branch -a --contains tags/<tag> git branch -a --contains <commit> 
like image 159
VonC Avatar answered Sep 21 '22 21:09

VonC