0
我得到使用JGit兩個分支之間的區別如下:JGit如何獲得RevCommit的名單DiffEntry
ObjectReader reader = git.getRepository().newObjectReader();
CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
Ref master = git.getRepository().exactRef(getRefBranchName(branchMaster));
RevTree masterTree = new RevWalk(git.getRepository()).parseTree(master.getObjectId());
oldTreeIter.reset(reader, masterTree.getId());
Ref release = git.getRepository().exactRef(getRefBranchName(branchRelease));
RevTree releaseTree = new RevWalk(git.getRepository()).parseTree(release.getObjectId());
newTreeIter.reset(reader, releaseTree.getId());
List<DiffEntry> diffs = git.diff().setNewTree(newTreeIter).setOldTree(oldTreeIter).call();
然後如下我可以打印文件的差異:
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
DiffFormatter formatter = new DiffFormatter (outputStream);
formatter.setRepository(git.getRepository());
for (DiffEntry entry: diffs){
System.out.println("Diff Entry: " + entry + ", from: " + entry.getOldId()+", to: " + entry.getNewId());
formatter.format(entry);
String diffText = outputStream.toString("UTF-8");
System.out.println(diffText);
outputStream.reset();
}
我看到的所有分歧在這個分支中的兩個文件之間,但是我怎樣才能得到所有這些差異的提交DiffEntry
?我還沒有找到辦法做到這一點
感謝您的幫助 – Evens