簡體   English   中英

Jgit遍歷特定分支的提交內容

[英]Jgit traverse content of a commit from specific branch

如何使用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");
}

這段代碼從提交中檢索了一個特殊文件,但我想遍歷提交的所有內容。

看到這個答案 ,它列出了文件和文件夾。 當您僅對文件路徑感興趣時,可以使用setRecursive(true)並離開isSubtree分支。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM