如何通过JGit与两个文件进行比较而不创建回购? [英] How to diff with two files by JGit without creating repo?
本文介绍了如何通过JGit与两个文件进行比较而不创建回购?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用JGit对两个文件进行 diff
时,我必须首先创建一个存储库.但是在Git中,我只需要使用命令 git diff --no-index 1.txt 2.txt
.
When I use JGit to diff
with two files, I must create a repo first. But in Git, I only need to use command git diff --no-index 1.txt 2.txt
.
是否可以在JGit中使用 diff
而不创建存储库?
Is there a way to use diff
in JGit without creating repo?
推荐答案
谢谢!我已经解决了这个问题!
thank you! I have solved this question!
private static String getDiff(String file1, String file2) {
OutputStream out = new ByteArrayOutputStream();
try {
RawText rt1 = new RawText(new File(file1));
RawText rt2 = new RawText(new File(file2));
EditList diffList = new EditList();
diffList.addAll(differ.diff(COMP, rt1, rt2));
new DiffFormatter(out).format(diffList, rt1, rt2);
} catch (IOException e) {
e.printStackTrace();
}
return out.toString();
}
感谢您的帮助!
thank you for your help!
这篇关于如何通过JGit与两个文件进行比较而不创建回购?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文