有没有办法列出已经提取但未使用LibGit2Sharp合并的提交?
例如,我可以运行以下git命令:
C:\Users\Tom\SourceLog>git log origin
commit f3beb4960b2f4bf5641d5b512b5b8c3081512a56
Author: Tom Hunter
Date: Wed Jan 9 22:58:51 2013 +0000
Rollback change to icon
Seemed to crash on windows xp for some reason..
commit d95f29a6cbfea9cb6009c3095a67d71f86d9e8bd
Author: Tom Hunter
Date: Mon Jan 7 21:34:36 2013 +0000
Updating Icon
commit 8785ed4ff3c46bef46ea6e2398c115b4b0203b2c
Author: Tom Hunter
Date: Mon Jan 7 21:22:54 2013 +0000
Fixing tests
Moved GenerateFlowDocuments method to LogEntry class.
Have somehow managed to greatly simplify tests..
...
前两个提交尚未合并到我的本地存储库中。即如果我遗漏原产地:
,这就是我得到的C:\Users\Tom\SourceLog>git log
commit 8785ed4ff3c46bef46ea6e2398c115b4b0203b2c
Author: Tom Hunter
Date: Mon Jan 7 21:22:54 2013 +0000
Fixing tests
Moved GenerateFlowDocuments method to LogEntry class.
Have somehow managed to greatly simplify tests..
...
以下代码仅给我8785ed。如何获得包含尚未合并的提交的列表?
using (var repo = new Repository(@"C:\Users\Tom\SourceLog"))
{
var c = repo.Commits.First();
}
答案 0 :(得分:4)
您可以使用以下命令获取远程原始分支的提交:
repo.Branches["origin/HEAD"].Commits
您可以使用First()
通过默认排序获取最新提交。但是,您获得远程分支的所有提交,而不仅仅是未合并的提交。
如果您想拥有未合并提交的集合,则应使用QueryBy(filter)
来获取提交。 nulltoken's asnwer描述了解决方案,但它包含错误。正确的用法是:
var filter = new Filter
{
Since = repo.Branches["origin/HEAD"],
Until = repo.Head
};
var notMergedCommits = repo.Commits.QueryBy(filter);
因为:
因此,使用上面的代码,您希望从分支"origin/HEAD"
获取提交,并排除"HEAD"
中包含的提交,这意味着返回获取的分支中的所有提交,而不是但已合并到"HEAD"
。