java - JGit 中具有更改历史记录的日志

标签 java git svn jgit

我正在尝试使用 JGit 显示文件更改历史记录。我设法获得了提交消息的历史记录。但是无法获得与每次提交相关的更改(如 git log -p),基本上我需要检查更改是什么...(如日志命令中的 +,-)

public void test() {

    try {
        File gitWorkDir = new File("/home/test/GITTEST/");
        Git git = null;
        git = Git.open(gitWorkDir);
        Repository repo = git.getRepository();
        LogCommand log = git.log();
        log.setMaxCount(2);
        Iterable<RevCommit> logMsgs = log.call();
        for (RevCommit commit : logMsgs) {
            System.out.println("----------------------------------------");
            System.out.println(commit);
            System.out.println(commit.getAuthorIdent().getName());
            System.out.println(commit.getAuthorIdent().getWhen());
            System.out.println(" ---- " + commit.getFullMessage());
            System.out.println("----------------------------------------");
            RevTree tree = commit.getTree();

TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(TreeFilter.ANY_DIFF);

//treeWalk.setFilter(PathFilter.create("."));
if (!treeWalk.next()) 
{
  System.out.println("Nothing found!");
  return;
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repo.open(objectId);
ByteArrayOutputStream out = new ByteArrayOutputStream();
loader.copyTo(out);
System.out.println("----" + out.toString());
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>----------------------------------------");    
        }
    } catch (Exception e) {
        System.out.println("no head exception : " + e);
    }
}

最佳答案

解决了以下使用 DiffFormatter http://codesnippetx.blogspot.com/

关于java - JGit 中具有更改历史记录的日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19628781/

相关文章:

git - 删除既不在子树中也不在原始存储库中的提交

svn - 颠覆: what does "Target path does not exist" when merging mean?

svn - 使用 TortoiseSVN 如何将更改从主干合并到分支,反之亦然?

JavaFX - TableView - 字段的变化和该字段的字段

java - intellij idea svn 插件 : how to show last user who modified the file in the project tree view

windows - 为什么 "go get gopkg.in/..."不工作而 "go get github.com/..."正常?

linux - Shell 脚本不会在 jenkins 上执行,但是它会手动执行

java - TreeSet 不添加超过两个项目(对象)

java - 为什么我会收到此错误 : E/ERROR: The executeQuery method must return a result set. ?

linux - 从 svnadmin hotcopy 创建 SVN 仓库