2017-06-08 53 views
1

我想查看自用戶最後一次從他們的機器推送以來的所有提交。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

您希望可以從c獲得的提交,但不包括可從遠程提交獲得的提交。

如果你正在談論master,在典型的設置中,跟蹤分支將是remotes/origin/master。當您推送到遠程master分支時,refs/remotes/origin/master將會更新。

所以你CommitFilter應該是這樣的:

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

即相當於git log refs/remotes/origin/master..c

相關問題