4

使用 JGit。需要知道分支的区别。如何运行命令 JGit API: git diff --name-status ..origin

4

1 回答 1

2

您可以通过为分支创建 AbstractTreeIterator 实例来使用 DiffCommand,然后使用 DiffCommand 返回两个分支之间差异的列表:

// the diff works on TreeIterators, we prepare two for the two branches
AbstractTreeIterator oldTreeParser = prepareTreeParser(repository, "refs/heads/oldbranch");
AbstractTreeIterator newTreeParser = prepareTreeParser(repository, "refs/heads/master");

// then the procelain diff-command returns a list of diff entries
List<DiffEntry> diff = new Git(repository).diff().setOldTree(oldTreeParser).setNewTree(newTreeParser).call();
for(DiffEntry entry : diff) {
    System.out.println("Entry: " + entry);
}

现在可以在我的 jgit-cookbook中找到包含创建 AbstractTreeIterator 的完整示例

于 2013-08-22T10:32:28.153 回答