mus*_*ium 4 c# git logging commit libgit2sharp
是否可以使用LibGit2Sharp获取指定提交后的所有提交?
我试过以下......但它不起作用:
using ( var repo = new Repository( repositoryDirectory ) )
{
//Create commit filter.
var filter = new CommitFilter
{
SortBy = CommitSortStrategies.Topological | CommitSortStrategies.Reverse,
Since = repo.Refs
};
/*Not Working
if (shaHashOfCommit.IsNotEmpty())
filter.Since = shaHashOfCommit;
*/
var commits = repo.Commits.QueryBy( filter );
}
Run Code Online (Sandbox Code Playgroud)
以下代码应符合您的期望.
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);
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1654 次 |
| 最近记录: |