c# - 如何使用 LibGit2Sharp 库获取特定选定分支的存储库名称

标签 c# github libgit2sharp

我们正在使用 LibGit2Sharp 库来处理 Github 中的提交。

问题:我们需要通过 LibGit2Sharp 库获取 Github 中选定分支的所有存储库名称。

哪个类将拥有特定分支的存储库名称集合。

我们搜索了下面的 LibGit2Sharp 文档,但我们没有得到任何想法。

http://www.nudoq.org/#!/Projects/LibGit2Sharp

任何人都可以提出任何解决方案。

最佳答案

免责声明:

在下面的回答中,我假设您的意思是:

We need to get all the branch names for the selected repository in Github through LibGit2Sharp library.

使用 Repository 类的 Branches 属性

以下程序使用 Repository.Branches 属性,然后对其进行迭代:

class Program
{
    // Tested with LibGit2Sharp version 0.21.0.176
    static void Main(string[] args)
    {
        // Load the repository with the path (Replace E:\mono2 with a valid git path)
        Repository repository = new Repository(@"E:\mono2");
        foreach (var branch in repository.Branches)
        {
            // Display the branch name
            System.Console.WriteLine(branch.Name);
        }
        System.Console.ReadLine();
    }
}

程序的输出将显示如下内容:

origin/mono-4.0.0-branch 
origin/mono-4.0.0-branch-ServiceModelFix
upstream/mono-4.0.0-branch-c5sr2

如果您需要分支的 RemoteUpstreamBranchCanonicalName 等其他内容,您可以使用相关属性。

关于c# - 如何使用 LibGit2Sharp 库获取特定选定分支的存储库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34805542/

相关文章:

c# - FiddlerCore 解码 sdch 响应

c# - 关注 ListView 控件的第一个元素 WPF

git - 将 pull 请求 merge 在一起

.Net Core VS2015,无法加载 DLL 'git2-785d8c4' : The specified module could not be found.(HRESULT 异常:0x8007007E)

c# - 尝试从另一个文本框更新一个文本框,反之亦然 C# Winforms

shell - 是否可以在我的 shell 文件中使用 GitHub secret ?

git - GitHub repos 上的最佳实践,用于 fork 或创建新分支

version-control - libgit2sharp 中的孤立分支

c# - libgit2sharp 删除远程分支

c# - 无法从程序集 xxx 加载类型 xxx