列出可通过给定提交的父链接访问的提交(如 `git rev-list`)

List commits that are reachable by following the parent links from the given commit (like `git rev-list`)

有没有办法像 git rev-list HEAD 那样使用 libgit2sharp 库列出所有可从 HEAD 访问的提交?

有一个函数 ReferenceCollectionException.ReachableFrom,但它 returns 指向特定提交的引用列表:

let repo = new Repository("C:\path\to\repo")
let c = repo.Lookup<Commit>("HEAD")
let commits = repo.Refs.ReachableFrom([c])

commits只包含4个元素:

[ refs/heads/vNext => "63f8d6d90f06f4578604b57502f2c6b8aabf4479"
, refs/remotes/origin/HEAD => refs/remotes/origin/vNext => "63f8d6d90f06f4578604b57502f2c6b8aabf4479"
, refs/remotes/origin/ntk/issue_953 => "d5ced8c64e5ea9f6ba2135a72d59da2208215c6c"
, refs/remotes/origin/vNext => "63f8d6d90f06f4578604b57502f2c6b8aabf4479"
]

但是 HEAD:

的嵌套父提交要多得多
>> git rev-list HEAD | wc -l
1730

下面的一段代码应该可以帮助您完成您想要的

var filter = new CommitFilter { Since = repo.Head };

foreach (var commit in repo.Commits.QueryBy(filter))
{
    Console.WriteLine(commit.Sha);
}