How to distinguish two files from JGit without creating a repo?

When I use JGit for diff with two files, I must first create a repo. But in Git, I need to use the git diff --no-index 1.txt 2.txt .

Is there a way to use diff in JGit without creating a repo?

+4
source share
2 answers

Thank you! I solved this issue!

below

 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!

+2
source

Hm I don’t exactly understand the question, but maybe you are looking for something like gitective that does this with its BlobUtils " Diff two files " for an easier task.

0
source

Source: https://habr.com/ru/post/1440944/


All Articles