1

When using git cat-file --batch-check with a given commit-id object, how can one determine what branches or tags a blob belongs to ?

Thank you

chz
  • 355
  • 1
  • 7
  • 21

1 Answers1

2

You can't—not "when using git cat-file", that is.

If you widen the question, you can get much closer: Which commit has this blob?

Once you have the commit hash IDs—and you say you're starting with commit hash IDs, so you may not even need to look up the blob hash IDs—you can get all containing branch names, for each commit hash ID, using git branch --contains. (Use git tag --contains or git tag --points-at for tags, depending on what you want for your answer; see also git for-each-ref as well, and VonC's suggestion of using git describe.)

Depending on which of the various solutions you like from the linked question, you can start from branch names before examining the tree associated with each commit to find whether that commit contains the blob; by working backwards from branch names, to commit hash IDs, you already know which branch name(s) contain that commit.

torek
  • 448,244
  • 59
  • 642
  • 775