gpt4 book ai didi

git - LibGit2Sharp - 传出和传入提交列表

转载 作者:行者123 更新时间:2023-12-05 06:34:51 25 4
gpt4 key购买 nike

我正在尝试找到一种简单的方法来查找传出提交(我已经在本地提交但仍需要 PUSH)和传入提交(我已经完成提取并发现远程上有提交但我还没有将它们 pull 到我的本地副本中)。

Diff 几乎做了我想要的,但我只想要提交的总数,而不是每个文件(例如 2 个传出提交,而不是 18 个修改的文件)。

请问在 LibGit2Sharp 中执行此操作的最佳方法是什么?

foreach (Repos r in config.Repos)
{
using (var repo = new Repository(r.LocalPath))
{
foreach (StatusEntry statusEntry in repo.RetrieveStatus())
{
..... I'm able to find info about my local differences here .....
}

var headTree = repo.Head.Tip.Tree;
var remoteMasterTree = repo.Branches["origin/master"].Tip.Tree;
var diffs = new Dictionary<ChangeKind, int>();
foreach (TreeEntryChanges treeEntryChange in repo.Diff.Compare<TreeChanges>(remoteMasterTree, headTree))
{
..... this is giving me each file, but I only want "2 outgoing commits" .....
}
}
}

最佳答案

我明白了!

    public IEnumerable<Commit> GetOutgoingCommits(Repository repo, String branchName = "master")
{
var branch = repo.Branches.FirstOrDefault(x => x.FriendlyName == branchName);

if (branch.TrackingDetails.AheadBy != null)
{
foreach (var commit in repo.Commits.Take(branch.TrackingDetails.AheadBy.Value))
{
yield return commit;
}
}
}

关于git - LibGit2Sharp - 传出和传入提交列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49986648/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com