简体   繁体   English

如何使用JGit获取提交的整个Java文件?

[英]How to use JGit to get the whole Java file of a commit?

In a commit, there are some java files have been revised. 在一次提交中,有一些Java文件已被修改。 For the each revised file in a commit, I want to get the whole file content of the revised file and the previous file (before revised). 对于提交中的每个修订文件,我想获取修订文件和先前文件(修订前)的全部文件内容。 Any ideas? 有任何想法吗? Thanks. 谢谢。

Basically you do a RevWalk with the commit-id and then a TreeWalk to get the actual file contents. 基本上,您可以使用commit-id进行RevWalk ,然后使用TreeWalk来获取实际的文件内容。

You can take a look at the example at https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/ReadFileFromCommit.java in my jgit-cookbook. 您可以在我的jgit-cookbook中的https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/api/ReadFileFromCommit.java中查看示例。 It shows how to fetch a file for a specific commit. 它显示了如何获取特定提交的文件。 Just call it with your filename instead of README.md once for each of the two commit-ish instead of HEAD to get the content of the two files. 只需使用您的文件名而不是README.md对其进行两次调用,而不是HEAD一次,即可获取两个文件的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM