19

Given a conflicted file foo.txt, how to tell git diff to show changes between the base version of the file and "their" version of the file?

I can see each of the versions via git show :1:foo.txt or git show:3:foo.txt - is there a simple way to compare the two versions?

Rafał Dowgird
  • 43,216
  • 11
  • 77
  • 90
  • 1
    This link shows how to view the patch that failed: http://stackoverflow.com/questions/2118364/how-to-identify-conflicting-commits-by-hash-during-git-rebase --ie, it explains how to see the "theirs" patch. – Eddified Feb 08 '13 at 19:36

2 Answers2

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

More info at man gitrevisions; look for :[<n>:]<path>.

brillout
  • 7,804
  • 11
  • 72
  • 84
jsageryd
  • 4,234
  • 21
  • 34
  • git must have introduced this syntax somewhere between today and the time I asked the question, thanks for the good news :) – Rafał Dowgird Feb 27 '13 at 09:01
  • This syntax has been available for many years. Just to be sure I tried it out in a rather ancient version (1.5.5) from April 2008 and it sure works. :) – jsageryd Feb 27 '13 at 09:46
  • I'd swear I tried that, so either I made some stupid typo or it was broken in a particular version. I guess I'll never know :) – Rafał Dowgird Feb 27 '13 at 10:54
  • To save some typing: `function gdf13 { git diff ":1:./$1" ":3:./$1"; }` – Ciro Santilli OurBigBook.com Dec 30 '14 at 17:44
  • 3
    Could anyone please point me to the documentation of this syntax for `git diff` and `git show`, i.e. `:1` and `:3`? I can't see it in documentation of `git diff` and `git show` – radix Jun 12 '18 at 11:41
  • 1
    [man gitrevisions](https://gitirc.eu/gitrevisions.html) look for `:[:]`. – jsageryd Jan 07 '20 at 19:41
1

Simply type git diff and it will show only the conflicts.

Further reading: Advanced Merging

Notice the --base and --theirs arguments for diff

Thomas Rawyler
  • 1,075
  • 7
  • 16