如何在 LibGit2Sharp 中执行 git diff --name-status origin/master...HEAD?

How to perform git diff --name-status origin/master...HEAD in the LibGit2Sharp?

我正在使用 LibGit2Sharp。如何使用以下参数调用 git diff 命令?

git diff --name-status origin/master...HEAD

我知道,git diff A...B 等同于 git diff $(git-merge-base A B) B

我找到了解决方法。你可以这样做:

1) 获取两个提交的共同祖先。

2) 获取树之间的差异。

var baseCommit = repo.ObjectDatabase.FindMergeBase(repo.Branches["origin/master"].Tip, repo.Head.Tip);
var diff = repo.Diff.Compare<TreeChanges>(baseCommit.Tree, repo.Head.Tip.Tree);