Reputation: 442
I'm newbie to JGit and am trying to create a program to perform git operations through JGit.
Is there any good example for JGit Merge, I've looked at https://github.com/centic9/jgit-cookbook/ but there only CheckMergeStatusOfCommit.java available that does not full fill my requirement.
Scenario:- I have a file on my remote say "abc.txt" as well as in my working repo. File is having conflicts, since on same line there is different text on remote and working repository.
How could i get the latest changes from my remote and merge them with the changes from working repo, I need changes from both (remote and working repo).
Please suggest.
Upvotes: 0
Views: 858
Reputation: 15880
I have created a corresponding sample as part of my jgit-cookbook at MergeChanges.java, the relevant code-snippet is something like this:
ObjectId mergeBase = repository.resolve("changes");
System.out.println("Merge-Results for id: " + mergeBase + ": " + merge);
for (Map.Entry<String,int[][]> entry : merge.getConflicts().entrySet()) {
System.out.println("Key: " + entry.getKey());
for(int[] arr : entry.getValue()) {
System.out.println("value: " + Arrays.toString(arr));
}
}
Update: Edited the snippet to show how merge-conflicts are returned, see also the JavaDoc for getConflicts()
Upvotes: 1