相关疑难解决方法(0)

如何使用JGit显示提交之间的更改

我试图在文件的两次提交之间显示一个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)

java jgit

9
推荐指数
1
解决办法
7572
查看次数

标签 统计

java ×1

jgit ×1