Jgit遍历特定分支的提交内容

时间:2014-01-27 12:50:13

标签: java git jgit

如何使用jgit遍历特定分支的特定提交的所有内容?

ObjectId commitId = repository.resolve(currentCommit.getCommitHash());
RevWalk revWalk = new RevWalk(repository);
RevCommit commit = revWalk.parseCommit(commitId);
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(currentPath));
if (!treeWalk.next()) {
    throw new IllegalStateException(
            "Did not find expected file README.md");
}

此代码从提交中检索一个特殊文件,但我想遍历提交的所有内容。

1 个答案:

答案 0 :(得分:2)

请参阅this answer,它列出了文件和文件夹。当您只对文件路径感兴趣时,可以使用setRecursive(true)并取消isSubtree分支。