繁体   English   中英

Libgit2Sharp :获取与初始(第一次)提交相关的文件

[英]Libgit2Sharp : Get files associated with the initial (first) commit

如何检索作为存储库第一次(初始)提交的一部分的文件?

我目前正在使用以下内容来找出作为提交一部分的文件(并且它有效)。 但是,由于该方法需要两个参数,我应该传递什么来获取属于第一次提交的文件? 或者我需要使用另一种方法吗?

    repo.Diff.Compare<TreeChanges>(repo.Commits.ElementAt(i).Tree, repo.Commits.ElementAt(i + 1).Tree)

谢谢!

您可以轻松地获取初始树和空树之间的差异来捕获文件:

foreach (TreeEntryChanges change in repo.Diff.Compare<TreeChanges>(null, commit.Tree))
{
     Console.WriteLine("\t{0} :\t{1}", change.Status, change.Path);
}

我能够使用以下方法实现我的要求:

                    //The tree object corresponding to the first commit in the repo
                    Tree firstCommit = repo.Lookup<Tree>(repo.Commits.ElementAt(i).Tree.Sha);
                    //The tree object corresponding to the last commit in the repo
                    Tree lastCommit = repo.Lookup<Tree>(repo.Commits.ElementAt(0).Tree.Sha);


                    var changes = repo.Diff.Compare<TreeChanges>(lastCommit, firstCommit);
                    foreach (var item in changes)
                    {
                        if (item.Status != ChangeKind.Deleted)
                        {
                            //...This object (i.e. item) corresponds to a file that was part of the first (initial) commit...
                        }
                    }

让我知道是否有更好的方法...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM