LibGit2Sharp日志远程 [英] LibGit2Sharp log remote

查看:144
本文介绍了LibGit2Sharp日志远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以列出已提取但未使用LibGit2Sharp进行合并的提交?



例如,我可以运行以下git命令:

C:\Users\Tom\SourceLog> git log origin
commit f3beb4960b2f4bf5641d5b512b5b8c3081512a56
作者:Tom Hunter
日期:Wed Jan 9 22:58:51 2013 +0000

回滚更改为图标

似乎在Windows XP中崩溃某些原因..

提交d95f29a6cbfea9cb6009c3095a67d71f86d9e8bd
作者:Tom Hunter
日期:Mon Jan 7 21:34:36 2013 +0000

更新图标

commit 8785ed4ff3c46bef46ea6e2398c115b4b0203b2c
作者:Tom Hunter
日期:Mon Jan 7 21:22:54 2013 +0000

修复测试

将GenerateFlowDocuments方法移至LogEntry类。
以某种方式设法极大地简化了测试..

...



前两个提交尚未合并到我的本地存储库中。即如果我忽略 origin

  C :\Users\Tom\SourceLog> git log 
commit 8785ed4ff3c46bef46ea6e2398c115b4b0203b2c
作者:Tom Hunter
日期:Mon Jan 7 21:22:54 2013 +0000

修复测试

将GenerateFlowDocuments方法移至LogEntry类。
以某种方式设法极大地简化了测试..

...



下面的代码只给我8785ed。如何获得包含尚未合并的提交列表?


$ b

using(var repo = new Repository(@C:\Users\Tom\SourceLog))
{
var c = repo.Commits.First();
}


解决方案

您的远程原籍分支:

  repo.Branches [origin / HEAD]。提交

$ b

您可以使用 First()获取默认排序的最新提交。但是,您可以获得远程分支的所有提交,而不仅仅是未合并的提交。



如果您想要收集未合并的提交,您应该使用 QueryBy(filter)来获取提交。 nulltoken's asnwer 描述了解决方案,但它包含一个错误。正确的用法是:

  var filter = new过滤
{
自= repo.Branches [原产地/ HEAD],
直至= repo.Head
};
var notMergedCommits = repo.Commits.QueryBy(filter);

因为:


  • 从以下版本开始:一个指向提交对象的指针或指向列表的指针。

  • 直到:指向提交对象的指针或枚举中将被排除的指针列表(以及祖先)



代码你希望从分支origin / HEAD提交并排除包含在HEAD这意味着返回提取分支中尚未合并到HEAD的所有提交。


Is there any way to list commits that have been fetched, but not merged using LibGit2Sharp?

For example I can run the following git command:

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..

...

The top two commits have not yet been merged into my local repository. I.e. this is what I get if I leave out origin:

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..

...

The following code gives me only 8785ed. How can I get a list including the yet-to-be merged commits?

using (var repo = new Repository(@"C:\Users\Tom\SourceLog"))
{
    var c = repo.Commits.First();
}

解决方案

You can get the commits of your remote origin branch with:

repo.Branches["origin/HEAD"].Commits

And you can use First() the get the latest commit by the default sorting. However you get all the commits of the remote branch not just the not merged one.

If you want to have a collection of the not merged commits you should use QueryBy(filter) to get the commits. nulltoken's asnwer described the solution but it contains an error. The correct usage is:

var filter = new Filter
{
    Since = repo.Branches["origin/HEAD"],
    Until = repo.Head
};
var notMergedCommits = repo.Commits.QueryBy(filter);

Because:

  • Since: A pointer to a commit object or a list of pointers to consider as starting points.
  • Until: A pointer to a commit object or a list of pointers which will be excluded (along with ancestors) from the enumeration.

So with the above code you want to have the commits from the branch "origin/HEAD" and exclude the ones which are included in your "HEAD" which means return all the commits which are in the fetched branch and not yet merged to the "HEAD".

这篇关于LibGit2Sharp日志远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆