如果我正确理解了您的问题,则希望在给定的日期范围内查找提交,然后阅读该提交的特定文件格式的内容。
假设每个日期只有一次提交,则可以使用
RevWalk来获取所需的提交:
try (RevWalk walk = new RevWalk(repo)) { walk.markStart(walk.parseCommit(repo.resolve(Constants.HEAD))); walk.sort(RevSort.COMMIT_TIME_DESC); walk.setRevFilter(myFilter); for (RevCommit commit : walk) { if (commit.getCommitter().getWhen().equals(date)) { // this is the commit you are looking for revWalk.parseCommit(commit); break; } }}我不确定是否
revWalk.parseCommit(commit);必须使用-
这取决于如何
RevWalk设置。尝试在不解析提交的情况下运行代码,如果找到了文件,则保留该文件。
现在您已经有了所需的提交,请使用
TreeWalk获取文件内容:
try (TreeWalk treeWalk = TreeWalk.forPath(repository, fileName, commit.getTree())) { InputStream inputStream = repository.open(treeWalk.getObjectId(0), Constants.OBJ_BLOB).openStream(); // use the inputStream}fileName保存到相关文件的存储库相对路径。



