简体   繁体   English

如何使用LibGit2Sharp从获取中获取远程更改列表

[英]How to get a list of remote changes from fetch using LibGit2Sharp

I am able to successfully fetch, pull, push, etc. using LibGit2Sharp, but I would like to be able to list files that have changed, added, etc. after doing a fetch. 我可以使用LibGit2Sharp成功获取,拉入,推送等内容,但是我希望能够在获取后列出已更改,添加等的文件。 I'm using https://github.com/libgit2/libgit2sharp/wiki/git-fetch and no errors or exceptions occur and logMessage is an empty string. 我正在使用https://github.com/libgit2/libgit2sharp/wiki/git-fetch ,没有错误或异常发生,并且logMessage是一个空字符串。

I would like to be able to show a list of changes like Visual Studio does when you perform a fetch. 我希望能够像执行Studio时显示的Visual Studio一样显示更改列表。

How can I use LibGit2Sharp to accomplish this? 如何使用LibGit2Sharp完成此操作?

Edit: I have read through the LibGit2Sharp Wiki and the LibGit2Sharp Hitchhiker's Guide to Git. 编辑:我已经阅读了LibGit2Sharp Wiki和LibGit2Sharp Hitchhiker的Git指南。 While I have tried some of the available commands to review what results they offer, I am not sure what the equivalent git command would be for this either. 虽然我尝试了一些可用的命令来查看它们提供的结果,但我不确定与此等效的git命令是什么。 It would be helpful to know and understand which command would provide this information and would be appreciated if you are familiar with Git, but not LibGit2Sharp. 了解和理解哪个命令可以提供此信息将很有帮助,如果您熟悉Git而不是LibGit2Sharp,将不胜感激。

Once the fetch is done, you can list the fetched commit of a given branch with 提取完成后,您可以使用列出给定分支的提取提交

git log ..@{u}

with @{u} designating the branch you are merging from (the upstream remote tracking branch, generally origin/yourbranch ) 使用@{u}指定您要合并的分支(上游远程跟踪分支,通常是origin/yourbranch

In LibGitSharp, that is what LibGit2Sharp/BranchUpdater.cs#UpstreamBranch reference (the upstream branch) 在LibGitSharp中,这就是LibGit2Sharp / BranchUpdater.cs#UpstreamBranch参考(上游分支)

With that, you should be able to list the commmits between your current branch HEAD and " UpstreamBranch ", a bit like in issue 1161 , but that issue was listing what is being pushed: let's invert the log parameters here. 这样,您应该能够列出当前分支HEAD和“ UpstreamBranch ”之间的命令,有点像问题1161一样 ,但是该问题列出了要推送的内容:让我们在这里反转日志参数。

var trackingBranch = repo.Head.TrackedBranch;
var log = repo.Commits.QueryBy(new CommitFilter 
            { IncludeReachableFrom = trackingBranch.Tip.Id, ExcludeReachableFrom = repo.Head.Tip.Id });

var count = log.Count();//Counts the number of log entries

//iterate the commits that represent the difference between your last 
//push to the remote branch and latest commits
foreach (var commit in log)
{
    Console.WriteLine(commit.Message);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM