[英]List commits that are reachable by following the parent links from the given commit (like `git rev-list`)
Is there a way to list all commits that are reachable from HEAD using libgit2sharp
library like git rev-list HEAD
do? 有没有办法使用git rev-list HEAD
使用libgit2sharp
库从HEAD可以访问的所有提交?
There is a function ReferenceCollectionException.ReachableFrom
, but it returns the list of refs pointed at particular commit: 有一个函数ReferenceCollectionException.ReachableFrom
,但是它返回指向特定提交的ReferenceCollectionException.ReachableFrom
列表:
let repo = new Repository("C:\path\to\repo")
let c = repo.Lookup<Commit>("HEAD")
let commits = repo.Refs.ReachableFrom([c])
And commits
contains only 4 elements: 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"
]
But there are much more nested parents commits of HEAD
: 但是还有更多的HEAD
嵌套父母的提交:
>> git rev-list HEAD | wc -l
1730
The following piece of code should help you accomplish what you're after 以下代码段应帮助您完成所追求的目标
var filter = new CommitFilter { Since = repo.Head };
foreach (var commit in repo.Commits.QueryBy(filter))
{
Console.WriteLine(commit.Sha);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.