【发布时间】:2020-03-13 11:44:49
【问题描述】:
存储库有几种类型的提交:
- 提交是分支头
- 作为标签引用的提交
- 第 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