如何使用LibGit2Sharp获取当前/活动分支? [英] How to get the current/active branch with LibGit2Sharp?

查看:114
本文介绍了如何使用LibGit2Sharp获取当前/活动分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,使用LibGit2Sharp https://github.com/libgit2/libgit2sharp ,您可以像这样遍历分支

So using LibGit2Sharp https://github.com/libgit2/libgit2sharp you can walk through the branches like this

using (var repo = new Repository(@"path to .git"))
{
    foreach (var branch in repo.Branches)
    {
        Debug.WriteLine(branch.Name);   
    }
}

但是如何获取当前/活动分支?

But how do I get the current/active branch?

推荐答案

Branch.IsCurrentRepositoryHead应该可以解决问题.

如果您不想遍历分支,我想Repository.Head也会做同样的事情...

I think Repository.Head will also do the same thing if you don't want to iterate through the branches...

这篇关于如何使用LibGit2Sharp获取当前/活动分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆