【问题标题】:How to make a diff branches with JGit?如何使用 JGit 制作差异分支?
【发布时间】:2013-08-21 08:06:23
【问题描述】:

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

【问题讨论】:

  • 您具体遇到了什么问题?你看过JGit API吗?
  • 是的,我使用了 JGit API。我不明白,如何运行命令git diff --name-status ..originDiffCommand

标签: branch diff jgit


【解决方案1】:

您可以通过为分支创建 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

【讨论】:

    猜你喜欢
    • 2012-08-07
    • 2018-04-15
    • 2014-07-26
    • 2016-02-01
    • 1970-01-01
    • 2017-06-23
    • 2016-11-03
    • 1970-01-01
    • 2022-01-05
    相关资源
    最近更新 更多