How to create diff branches with JGit?

Use JGit. You need to know the difference in branches. How to run the JGit API command: git diff -name-status..origin

+4
source share
1 answer

You can use DiffCommand by creating AbstractTreeIterator branches for branches, and then use DiffCommand to return you a list of differences between the two branches:

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

A complete example involving the creation of AbstractTreeIterator can now be found as part of my jgit-cookbook

+1
source

Source: https://habr.com/ru/post/1498145/


All Articles