How to list branches that contain a given commit in git2go (libgit2)?

你离开我真会死。 提交于 2019-12-13 05:56:37

问题


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>.


回答1:


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.



来源:https://stackoverflow.com/questions/31527908/how-to-list-branches-that-contain-a-given-commit-in-git2go-libgit2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!