简体   繁体   中英

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)

在此处输入图片说明

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 !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM