libgit2sharp获取自上次推送以来的所有提交

时间:2017-06-08 15:22:40

标签: c# git libgit2 libgit2sharp

我想查看自用户上次从他们的计算机上推送以来的所有提交。

    using (var repo = new Repository(repositoryDirectory))
{
    var c = repo.Lookup<Commit>(shaHashOfCommit);

    // Let's only consider the refs that lead to this commit...
    var refs = repo.Refs.ReachableFrom(new []{c});

   //...and create a filter that will retrieve all the commits...
    var cf = new CommitFilter
    {
        Since = refs,       // ...reachable from all those refs...
        Until = c           // ...until this commit is met
    };

    var cs = repo.Commits.QueryBy(cf);

    foreach (var co in cs)
    {
        Console.WriteLine("{0}: {1}", co.Id.ToString(7), co.MessageShort);
    }       
}

我从另一篇文章中获得了此代码,但我不确定如何修改它以获取自上次推送日期以来的提交。

1 个答案:

答案 0 :(得分:-1)

您希望从c可以访问的提交,不包括从远程提交可以访问的提交。

如果您正在谈论master,在典型设置中,此跟踪分支将为remotes/origin/master。当您推送到远程refs/remotes/origin/master分支时,master将会更新。

所以你的CommitFilter应该是这样的:

new CommitFilter { Since = repo.Refs["refs/remotes/origin/master"], Until = c }

相当于git log refs/remotes/origin/master..c