【问题标题】:How to get all git commits with libgit2sharp, regardless the branch?无论分支如何,如何使用 libgit2sharp 获取所有 git 提交?
【发布时间】:2021-08-18 04:18:38
【问题描述】:

AFAIK,Repository.Commits 属性返回当前分支可访问的所有提交。

我想获得所有可能的提交,不管分支。 我正在使用以下命令:

var commitsToRewrite = repository.Branches.SelectMany(x => x.Commits)
                .GroupBy(x => x.Sha)
                .Select(x => x.First())
                .ToArray();

它很慢,但似乎有效(也许我错过了一些未涵盖的特殊情况)。 这是正确的做法吗?有没有更高效、更快的方法?

【问题讨论】:

    标签: c# git git-commit libgit2sharp git-history-rewrite


    【解决方案1】:

    也许不是你的情况,但在极少数情况下,我发现只有遍历所有分支才能跳过一些提交(可能是分支删除的原因)。这段代码似乎做得更好(希望如此),而且速度更快,内存占用更少。

    var commitsToRewrite = repository.Commits.QueryBy(new CommitFilter {IncludeReachableFrom = repository.Refs.ToList()})
                            .Distinct<Commit>(EqualityComparer<GitObject>.Default)
                            .ToList();
    

    我使用具有超过 85000 次提交和 500Mb 的 ReactOS git repo 对此进行了测试。

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 1970-01-01
      • 2014-10-10
      • 2020-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      相关资源
      最近更新 更多