codelab codelab - 3 months ago 19
Git Question

How to retrieve the branch where a commit was created originally using LibGit2Sharp?

how can I retrieve the branch where a commit was created originally using LibGit2Sharp?
Assumed that I have two branches (development, feature1 ) which have several commits and are merged some time later. When I retrieve all commits and the branches they are belonging every commit is linked with the two branches. So it is not possible to determine which is the original source branch.

Thank you!

Answer

Git does not store any such information, which means it is not retrievable, no matter what access method you use.

Branch names are largely ephemeral and can be created and destroyed whenever you like, with one caveat: a commit that is not reachable by any name is subject to garbage-collection. But if a commit C is reachable from branch names B1, B2, B3 then commit C is contained within all three branches. Remove name B2 and commit C is now contained within branches B1 and B3.

(The name that protects a commit need not be a branch name. A tag name, or a stash reference, or a remote-tracking branch name, or any other name anywhere in the refs name-space, suffices to protect a commit. [This is not a complete list but covers all the normal reliable cases.] This rule applies recursively to all other protected commits as well: if commit C is reachable from protected commit P, then C is also protected, and C in turn protects all commits reachable from C.)

Comments