Efficient way to find out which branches and/or commits point to an object?
Given a git object, is there a way to traverse upwards to find all commits and/or branches which point to it, or are they only linked in one direction? E.g.:
BLOB1 ---- \ BLOB2 ----- C1 ---- C2 ---- B1 \ ---- C3 ---- B2
B1, can I traverse down to
BLOB2, and then traverse back up to locate
B2 (and any other branches which point to the same blob)? Or do I have to inspect all branches?
One Solution collect form web for “Efficient way to find out which branches and/or commits point to an object?”
You can only “traverse down” the relationship graph as you describe it, but not “back up”, because all object relations in this context are unidirectional associations (i.e. a commit knows only its parents, but not its children; a tree knows its blobs but blobs don’t know what trees reference them).
The only way to find out which commits include a specific blob is thus to traverse the complete history graph (the entry points are your named refs, i.e. branches and tags).
This is the same thing that
git gc does to determine orphaned objects to be garbage-collected.