如何列出在git2go(libgit2)中包含给定提交的分支? [英] How to list branches that contain a given commit in git2go (libgit2)?

查看:230
本文介绍了如何列出在git2go(libgit2)中包含给定提交的分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个特定的引用(本例中是一个标签),如何在 git2go ?类似于 git branch --contains< commit>

解决方案

图形方面的问题是我怎么知道A是B的祖先? (对于你想成为B的每个分支重复几次)。要回答这个问题的唯一方法就是沿着从B开始的历史记录图,并检查是否找到A.



您可以通过几种方式完成此操作,但最效率通常会降低问题的等同性是A和B的合并基础?。你可以通过 Repository.MergeBase()在git2go中提出这个问题。这将返回您提交的两个提交之间的最佳合并基础。如果您希望将其中一个提交作为合并基础,则应始终提供正确答案,即使它将答案缩减为单个合并基础。


Given a specific reference (a tag in this case) how can you list the branches that contain that commit in git2go? Similar to git branch --contains <commit>.

解决方案

The question here, graph-wise is "how do I know if A is an ancestor of B?" (repeated a few times for each branch which you want to be B). The only way to answer that is to walk down the history graph starting at B and check if you find A.

You can do this in a few ways, but the most efficient is generally going to be to reduce the question to the equivalent "is A a merge-base of A and B?". You can ask this question in git2go via Repository.MergeBase(). This will return the best merge-base between the two commits you give it. In the case where you want one of the commits to be the merge base, this should always provide the right answer, even though it cuts the answer down to a single merge base.

这篇关于如何列出在git2go(libgit2)中包含给定提交的分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆