简体   繁体   English

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

[英]libgit2sharp get all commits since the last push

I would like to view all of the commits since the last time the user pushed from their machine.我想查看自用户上次从他们的机器推送以来的所有提交。

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

I got this code from another post, but I am not sure how to modify it to get the commits since the date of the last push.我从另一篇文章中得到了这段代码,但我不知道如何修改它以获取自上次推送日期以来的提交。

You want the commits that are reachable from c , excluding the ones that are reachable from the remote commit.您需要可从c访问的提交,不包括可从远程提交访问的提交。

If you're talking about master , in a typical setup, the tracking branch for this will be remotes/origin/master .如果你在谈论master ,在典型的设置中,它的跟踪分支将是remotes/origin/master refs/remotes/origin/master will be updated when you push to the remote master branch. refs/remotes/origin/master将在您推送到远程master分支时更新。

So your CommitFilter should look like:所以你的CommitFilter应该是这样的:

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

Which is equivalent to git log refs/remotes/origin/master..c .这相当于git log refs/remotes/origin/master..c

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

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