Libgit2Sharp:获取两个标签之间的文件列表

时间:2017-04-18 10:25:06

标签: c# libgit2sharp

我们在下面给出了一个Git bash命令,它获取github中2个标签之间的已提交文件列表,

git log tag1 tag2 --stat

有人能为它提供等效的Libgit2Sharp代码吗?

1 个答案:

答案 0 :(得分:0)

试试这个:git log tag1 tag2 --stat

        using (var repo = new Repository(@"repoPath"))
        {
            Tag tagTo  = repo.Tags["tag2"];
            Tag tagFrom  = repo.Tags["tag1"];

            var commitFrom = repo.Lookup<LibGit2Sharp.Commit>(tagFrom.Target.Sha);
            var commitTo = repo.Lookup<LibGit2Sharp.Commit>(tagTo.Target.Sha);

            TreeChanges treeChanges = repo.Diff.Compare<TreeChanges>(commitFrom.Tree, commitTo.Tree);
        }

但是当你只想在标签之间提交时:git log tag1 tag2你可以使用:

        using (var repo = new Repository(@"repoPath"))
        {
            Tag tagTo  = repo.Tags["tag2"];
            Tag tagFrom  = repo.Tags["tag1"];

            var filter = new CommitFilter();

            filter.IncludeReachableFrom = tagTo.Target.Sha;
            filter.ExcludeReachableFrom = tagFrom.Target.Sha;

            var commits = repo.Commits.QueryBy(filter).ToList();
        }