我们正在使用 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
如果您需要分支的 Remote
或 UpstreamBranchCanonicalName
等其他内容,您可以使用相关属性。
关于c# - 如何使用 LibGit2Sharp 库获取特定选定分支的存储库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34805542/