6

Say, I've been presented with a merge conflict, and I managed to fix it, but haven't marked as resolved (i.e. I haven't done git add conflicted files yet). At this point, I can do git diff and I'll be shown how the resultant file differs from each parent, in a combined diff format.

All good so far. Now I wanted to separately inspect how resultant file differs from individual parent. Sure, for a merge conflict involving 2 parents (cherry-pick, rebase etc.), I can use git diff --ours or git diff --theirs, but how do I extend this to more parents?

In other words, if I get conflict from 3 parents, is it possible to view individual diffs w.r.t each parent?

Also, my discovery of --ours and --theirs was rather serendipitous; I couldn't find their usage documented in a diff context.

Jeenu
  • 2,109
  • 2
  • 20
  • 27
  • 4
    You could `diff` a working tree with any particular commit in the repo. Is this enough for you? – user3159253 Nov 12 '15 at 11:56
  • 1
    If file is still marked as 'C (conflicted)' you may need to manually `git reset` it, and then you can `git diff` it with any version you want. – Igal S. Nov 12 '15 at 14:01
  • Possible duplicate of [Show parents of uncommitted merge in git](http://stackoverflow.com/questions/13590740/show-parents-of-uncommitted-merge-in-git) – max630 Feb 16 '16 at 19:36
  • Just an advice. Try using "rebase" instead of merge, whenever possible. It will make your life a lot easier... – Mladen B. Nov 04 '16 at 14:03

1 Answers1

2

If

git diff :1:foo.txt :3:foo.txt

does not do what you want, I guess you have to do

git ls-files -u

and the use git show $sha1 > $sha1.txt to create some temporary files and compare those.

See also: Git compare "base" version with "theirs" version of a conflicted file?

Mikko Rantalainen
  • 14,132
  • 10
  • 74
  • 112