1

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.

Jacob Alley
  • 767
  • 8
  • 34

1 Answers1

-1

You want the commits that are reachable from c, excluding the ones that are reachable from the remote commit.

If you're talking about master, in a typical setup, the tracking branch for this will be remotes/origin/master. refs/remotes/origin/master will be updated when you push to the remote master branch.

So your CommitFilter should look like:

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

Which is equivalent to git log refs/remotes/origin/master..c.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187