Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » How to use Git diff options
How to use Git diff options [message #1791169] Mon, 25 June 2018 12:43 Go to next message
Muhammad Umar Ashraf is currently offline Muhammad Umar AshrafFriend
Messages: 1
Registered: June 2018
Junior Member
I'm using JGit Api's to get diff between commits, so how can I make use of Git diff options with JGit Api's e.g. like git diff --unified=n?

Here's the code snippet:

File gitWorkDir = new File("C:/temp/code/");
Git git =;

String oldHash = "d7db296cc2730ca562f91cfa539d6955a21284b6";

ObjectId headId = git.getRepository().resolve("HEAD^{tree}");
ObjectId oldId = git.getRepository().resolve(oldHash + "^{tree}");

ObjectReader reader = git.getRepository().newObjectReader();

CanonicalTreeParser oldTreeIter = new CanonicalTreeParser();
oldTreeIter.reset(reader, oldId);
CanonicalTreeParser newTreeIter = new CanonicalTreeParser();
newTreeIter.reset(reader, headId);

List<DiffEntry> diffs= git.diff()

ByteArrayOutputStream out = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(out);

for(DiffEntry diff : diffs)
String diffText = out.toString("UTF-8");

Re: How to use Git diff options [message #1791597 is a reply to message #1791169] Mon, 02 July 2018 16:55 Go to previous message
Thomas Wolf is currently offline Thomas WolfFriend
Messages: 204
Registered: August 2016
Senior Member
DiffFormatter.setContext() is your friend.
Previous Topic:ssh connection using an ECDSA key fails on second attempt (auth failed)
Next Topic:Help: My Push was rejected
Goto Forum:

Current Time: Mon Mar 30 14:44:10 GMT 2020

Powered by FUDForum. Page generated in 0.01973 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top