During a merge, the conflicting files are in a special state. There exists multiple entries with the same filename and different blob id's. These are usually three blobs (used for the three way merge) or two blobs (for a simple merge).
Attempt the merge..
$ git merge origin/otherbranch
Merge remote-tracking branch 'origin/otherbranch' into mybranch
Conflicts:
somefile.txt
Review the files which need merging
$ git diff --name-status --diff-filter=U
U somefile.txt
or
$ git update-index --refresh
somefile.txt: needs merge
Review the blobs which relate to the file being merged;
$ git ls-files -s somefile.txt
100644 9a0579524e0c7ba9fc9ae18badadaddcad2d598f **1** somefile.txt
100644 1bcff16b6de5ed304a06e643070e40787db1ead8 **2** somefile.txt
100644 6e52271b22f6a6d1150619433551e0fa9094b108 **3** somefile.txt
According to the git-merge man-page. 1 = common ancenstor, 2 = HEAD (ours) and 3 = MERGE_HEAD (theirs)
Show differences
$ git diff 9a0579524e0c7ba9fc9ae18badadaddcad2d598f 6e52271b22f6a6d1150619433551e0fa9094b108
< some differences >
Retrieve the common ancestor..
$ git cat-file blob 9a0579524e0c7ba9fc9ae18badadaddcad2d598f
Checkout version from HEAD
$ git checkout --ours somefile.txt
checkout version from MERGE_HEAD
$ git checkout --theirs somefile.txt
Reset to 'merged' changed
$ git checkout -m somefile.txt
Update:
This has simplified somewhat with the use of <ref>:ID:Filepath
eg
git diff :1:somefile.txt :2:somefile.txt
Will give you the difference between the two parents in a merge.
0 represents a completed merge
1 represents a conflicting merge
2/3 represent the two parents of the merge.
If you have a completed merge at a particular commit xxxxxx
, you can refer to its parents using xxxxxx^0
(merged file) xxxxxx^1
"left" parent, and xxxxxx^2
"right" parent. Comparing the merged files to its ancestors can be done as follows;
git diff xxxxxx^0:somefile xxxxxx^1:somefile