gpt4 book ai didi

c# - 如何获取包含 libgit2sharp 中提交的远程分支列表

转载 作者:太空宇宙 更新时间:2023-11-03 23:03:34 24 4
gpt4 key购买 nike

在 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();
}

关于c# - 如何获取包含 libgit2sharp 中提交的远程分支列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42156799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com