我试图在文件的两次提交之间显示一个git diff.基本上,我这样做是为https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java
您可以在https://github.com/svenhornberg/JGitDiff下查看我的完整代码
public class RepoDiff {
public void compare(byte[] fileContentOld, byte[] fileContentNew) {
try {
Repository repository = createNewRepository();
Git git = new Git(repository);
// create the file
commitFileContent(fileContentOld, repository, git, true);
commitFileContent(fileContentNew, repository, git, false);
// The {tree} will return the underlying tree-id instead of the commit-id itself!
ObjectId oldHead = repository.resolve("HEAD^^^^{tree}"); //here is my nullpointer
ObjectId head = repository.resolve("HEAD^{tree}");
System.out.println("Printing diff between tree: " + oldHead + " and " + head);
// prepare …Run Code Online (Sandbox Code Playgroud)