【问题标题】:How to get the current branch with LibGit2Sharp?如何使用 LibGit2Sharp 获取当前分支?
【发布时间】:2020-03-09 14:21:56
【问题描述】:

即使该目录不是 repo 的根目录,我如何获取特定目录的分支?相当于

git branch --show-current

(即使在子目录中也能正常工作)。

按照this similar question 的回答,我做了以下操作,它只适用于回购的根目录:

using (var git = new Repository("repo_root\subdir")) // throws if subdir
{
  return git.Head.FriendlyName;
}

【问题讨论】:

    标签: libgit2sharp


    【解决方案1】:

    糟糕,找到了:

    using (var git = new Repository(
      LibGit2Sharp.Repository.Discover(@"repo_root\subdir")))
    {
      return git.Head.FriendlyName;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-18
      • 1970-01-01
      • 2020-06-05
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      相关资源
      最近更新 更多