Home > database >  Which branch is behind the tag?
Which branch is behind the tag?

Time:09-01

I'm in a cloned source-tree created by using a tag. How do I determine, which branch is it, that the tagging was applied to -- so that I can pull in newer commits made into that branch?

The git branch command simply gives the name of the tag:

* (detached from the_tag_name)
  master

Thanks!

CodePudding user response:

Ok, here is, how I solved this for now -- but, I'm sure, there is a better way:

% git branch -v
* (detached from the_tag_name) HASH1 Commit-message1
  master                       HASH2 Commit-message2

I then followed up with:

% git branch -r --contains HASH1

The above command lists all branches, local and remote (thanks to the -r), that have the particular commit in them. In my case, there was only one such branch...

Hoping for a better solution from git gurus...

CodePudding user response:

How do I determine, which branch is it, that the tagging was applied to...

You can't, at least not for sure, and by using Git alone. As you already know, you can see what branches contain the tag(ged commit) right now, but this sort of history isn't stored in a clone. Note there is no requirement that a tag be on any branch at all! It could be otherwise orphaned, but will still show up in a clone.

There are some possibilities that might get you close:

  1. If the tag is so new that it hasn't shown up on other branches yet, then looking right now may reveal which branch it's on. If you set up a continuous fetch monitor you may be able to isolate the branch the tag shows up with, which would be a good (but not perfect) indicator of the branch it was created on.
  2. Some tools maintain a push history. This would be similar to a built-in monitor described in #1.
  3. If you have access to the computer that created the tag, you may be able to search the reflog on that machine to see what branch the repo had checked out at the time the tag was created.
  • Related