libgit2sharp得到所有提交自上次推(libgit2sharp get all commit

2019-09-29 22:47发布

我想查看所有提交的自最后一次用户从他们的机器推。

    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);
    }       
}

我从另一张贴此代码,但我不知道如何修改它来获得提交自上次推的日期。

Answer 1:

你想要的是到达从提交c ,排除可达来自远程提交的。

如果你在谈论master ,在一个典型的设置,这种情况的跟踪分行将remotes/origin/masterrefs/remotes/origin/master ,当你推到远程将被更新master分支。

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

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

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



文章来源: libgit2sharp get all commits since the last push