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

时间:2017-10-27 13:41:23

标签: c# git libgit2 libgit2sharp

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

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

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

1 个答案:

答案 0 :(得分:2)

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

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);