Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get thr branch of a commit with nodegit

I'm trying to know how I can get the branch in which a commit was created in (not the head). I know a branch is just a 'tag' attached to a commit (the head of that branch)

enter image description here

For example, in this image, what would I need to do to get the branch of the node E using nodegit or another git library.

I looked in the documentation, but I didn't find an equivalent to git branch --contains

Thanks !

like image 334
R00t Avatar asked Dec 19 '25 22:12

R00t


1 Answers

You'd have to:

  1. Iterate over all the branches.
  2. Find the ancestor of each branch's tip against the commit with NodeGit.Merge.base(repository, branchTip, interestedCommit).
  3. Then if the returnedCommit === interestedCommit then you're fine
like image 104
rcjsuen Avatar answered Dec 21 '25 10:12

rcjsuen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!