【问题标题】:Proper way to find commit by sha with LibGit2Sharp使用 LibGit2Sharp 查找 sha 提交的正确方法
【发布时间】:2020-03-13 11:44:49
【问题描述】:

存储库有几种类型的提交:

  1. 提交是分支头
  2. 作为标签引用的提交
  3. 第 1、2 和 3 点提交的父级。

如何通过 SHA 号正确查找提交?

我目前的解决方案:

return (Commit)repo.ObjectDatabase
  .First(o =>
    o.GetType() == typeof(Commit) &&
    o.Sha.Equals(shortSha, StringComparison.InvariantCultureIgnoreCase));

我当前的解决方案是遍历所有 git 对象,搜索需要一段时间。

我认为这里一定有更好的方法。

【问题讨论】:

  • 为什么你使用Repository.ObjectDatabase而不是Repository.Commits
  • 因为Repository.Commits 只包含当前头部和它的父母。

标签: c# git libgit2sharp


【解决方案1】:
return repo.Lookup<Commit>(sha);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-02-26
    • 1970-01-01
    • 2020-11-10
    • 2023-03-29
    • 2014-06-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多