如何使用JGit进行diff分支?

使用J
Git.需要知道分支机构的差异.

如何运行命令JGit API:

 git diff –name-status ..origin 最佳答案 您可以通过为分支创建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);
}

现在可以找到包括创建AbstractTreeIterator的完整示例as part of my jgit-cookbook

点赞