0

Is there a way of getting the info about branch (using libgit2 library), ideally git_reference* from git_commit* ?

What I'm trying to do is basically a getting info about a branch from a commit.

Thank you

There is nothing we can do
  • 21,267
  • 27
  • 92
  • 184

1 Answers1

1

No, there is no way to do this. Git commits are not "on" a branch, instead a branch is a pointer to a commit. So the data storage goes the opposite direction. As a result, many branches may point to the same commit, so there would be no way to get a single branch from a commit.

You could find all branches that contain a given commit, but due to the rather vague nature of this, it's not functionality that libgit2 provides. You could certainly implement it yourself using libgit2, by revwalking the branches that you're interested in to see if the given commit is found. But it will be very disappointing, performance-wise.

Edward Thomson
  • 63,947
  • 11
  • 134
  • 169