Java JGit中包含更改历史记录的日志
我正在尝试使用JGit显示文件更改历史记录。我设法获得了提交消息的历史记录。但是无法获得与每次提交相关的更改(如Java JGit中包含更改历史记录的日志,java,git,svn,jgit,Java,Git,Svn,Jgit,我正在尝试使用JGit显示文件更改历史记录。我设法获得了提交消息的历史记录。但是无法获得与每次提交相关的更改(如git log-p),基本上我需要检查更改是什么。。。(如日志命令中的+,-in) 公共无效测试(){ 试一试{ File gitWorkDir=新文件(“/home/test/GITTEST/”); Git Git=null; git=git.open(gitWorkDir); Repository repo=git.getRepository(); LogCommand log=g
git log-p
),基本上我需要检查更改是什么。。。(如日志命令中的+,-in)
公共无效测试(){
试一试{
File gitWorkDir=新文件(“/home/test/GITTEST/”);
Git Git=null;
git=git.open(gitWorkDir);
Repository repo=git.getRepository();
LogCommand log=git.log();
log.setMaxCount(2);
Iterable logMsgs=log.call();
for(RevCommit提交:logMsgs){
System.out.println(“--------------------------------------------------------”;
System.out.println(提交);
System.out.println(commit.getAuthorIdent().getName());
System.out.println(commit.getAuthorIdent().getWhen());
System.out.println(“---”+commit.getFullMessage());
System.out.println(“--------------------------------------------------------”;
RevTree-tree=commit.getTree();
TreeWalk TreeWalk=新TreeWalk(回购);
树路。添加树(树);
treeWalk.setRecursive(true);
treeWalk.setFilter(TreeFilter.ANY_DIFF);
//treeWalk.setFilter(PathFilter.create(“.”);
如果(!treeWalk.next())
{
System.out.println(“未找到任何内容!”);
返回;
}
ObjectId ObjectId=treeWalk.getObjectId(0);
ObjectLoader=repo.open(objectId);
ByteArrayOutputStream out=新建ByteArrayOutputStream();
加载程序。复制到(输出);
System.out.println(“---”+out.toString());
System.out.println(“>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>----------------------------------------------”;
}
}捕获(例外e){
System.out.println(“无头异常:+e”);
}
}
如果没有简单的方法通过纯java显示补丁,您可以使用idea类,该类封装对git的调用
作为包装器,它确实有
-p
选项。在下面使用DiffFormatter解决
感谢VonC,使用Logcommand,我可以通过ifle信息获取提交信息。这些信息只是文字,无法确定是什么原因造成的change@lakmal我同意。我只看到
org.eclipse.jgit.pgm.Log
能够显示这些补丁信息,以及基于DiffFormatter的Log.interest解决方案+1.
public void test() {
try {
File gitWorkDir = new File("/home/test/GITTEST/");
Git git = null;
git = Git.open(gitWorkDir);
Repository repo = git.getRepository();
LogCommand log = git.log();
log.setMaxCount(2);
Iterable<RevCommit> logMsgs = log.call();
for (RevCommit commit : logMsgs) {
System.out.println("----------------------------------------");
System.out.println(commit);
System.out.println(commit.getAuthorIdent().getName());
System.out.println(commit.getAuthorIdent().getWhen());
System.out.println(" ---- " + commit.getFullMessage());
System.out.println("----------------------------------------");
RevTree tree = commit.getTree();
TreeWalk treeWalk = new TreeWalk(repo);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(TreeFilter.ANY_DIFF);
//treeWalk.setFilter(PathFilter.create("."));
if (!treeWalk.next())
{
System.out.println("Nothing found!");
return;
}
ObjectId objectId = treeWalk.getObjectId(0);
ObjectLoader loader = repo.open(objectId);
ByteArrayOutputStream out = new ByteArrayOutputStream();
loader.copyTo(out);
System.out.println("----" + out.toString());
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>----------------------------------------");
}
} catch (Exception e) {
System.out.println("no head exception : " + e);
}
}