如何在JGit中“捕获”文件?

如何在JGit中“捕获”文件?,第1张

如何在JGit中“捕获”文件?

不幸的是,Thilo的答案不适用于最新的JGit API。这是我找到的解决方案

File repoDir = new File("test-git");// open the repositoryRepository repository = new Repository(repoDir);// find the HEADObjectId lastCommitId = repository.resolve(Constants.HEAD);// now we have to get the commitRevWalk revWalk = new RevWalk(repository);RevCommit commit = revWalk.parseCommit(lastCommitId);// and using commit's tree find the pathRevTree tree = commit.getTree();TreeWalk treeWalk = new TreeWalk(repository);treeWalk.addTree(tree);treeWalk.setRecursive(true);treeWalk.setFilter(PathFilter.create(path));if (!treeWalk.next()) {  return null;}ObjectId objectId = treeWalk.getObjectId(0);ObjectLoader loader = repository.open(objectId);// and then one can use eitherInputStream in = loader.openStream()// orloader.copyTo(out)

我希望它更简单。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5438848.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-11
下一篇 2022-12-11

发表评论

登录后才能评论

评论列表(0条)

保存