簡體   English   中英

如何獲取libgit2sharp中包含提交的遠程分支列表

[英]How to get list of remote branches that contain a commit in libgit2sharp

在git中我可以運行命令:

git branch -r --contains '#commit-hash#'

其中列出了我感興趣的提交的遠程分支。

我已經閱讀了libgit2sharp wiki上的文檔,但是那個例子有本地分支?

我怎樣才能在libgit2sharp中做同樣的事情?

查看libgit2wiki文檔后,您可以將其示例代碼修改為如下所示:

using (var repo = new Repository("path/to/your/repo"))
{
    const string commitSha = "5b5b025afb0b4c913b4c338a42934a3863bf3644";
    foreach(Branch b in ListBranchesContainingCommit(repo, commitSha))
    {
        Console.WriteLine(b.Name);
    }
}

private IEnumerable<Branch> ListBranchesContainingCommit(Repository repo, string commitSha)
{
    var commit = repo.Lookup<Commit>(commitSha);var commit = repo.Lookup<Commit>(commitSha);

    IEnumerable<Reference> headsContainingTheCommit = repo.Refs.ReachableFrom(repo.Refs, new[] {commit});
    return headsContainingTheCommit.Select(branchRef => repo.Branches[branchRef.CanonicalName]).ToList();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM