58

I have FileA in branchA and FileB in branchB.

The problem is that I can access only one file at time. I would like to be able to compare the files by FileMerge or meld, since they are the only diffTools whichI have found for Mac.

How can you diff by meld/FileMerge the two files?


[Solved]: 1st developed Problem: FileMerge does not allow standard input

Masi: You can use opendiff to allow FileMerge to have files from standard input. So the next problem is to find how to make git's diff tool to use opendiff.


2nd developed Problem: to make Git's diff tool to use opendiff in Mac

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

4 Answers4

67

You can use "git mergetool" for merging, and in modern git (meaning version 1.6.3 and later) "git difftool" for comparing using graphical tools. Of course you would have to configure them first, but they do some autodetection (with some hardcoded preference, of course), and if I remember correctly opendiff support is built in.

And then of course you would be able to use your graphical tool (opendiff / FileMerge) as you would use ordinary "git diff", for example

prompt> git difftool somebranch:UNREADME otherbranch:README
CB Bailey
  • 755,051
  • 104
  • 632
  • 656
Jakub Narębski
  • 309,089
  • 65
  • 217
  • 230
61

git supports branch names as part of the repository paths. Eg if you have the following files in your repository, README only on master, and UNREADME only on branch:

master:README

branch:UNREADME

You can diff them via git with:

git diff branch:UNREADME master:README

You can get a repository artifact to standard output with git show:

git show branch1:UNREADME

So if your external diff utility can take 2 files on the bash prompt, you can diff them with something like:

diff-command <(git show branch1:UNREADME) <(git show master:README)

Where the <(...) bash syntax takes the output of the enclosed command, runs it in a pipe and places the file path of the pipe on the command line.

Kyle Burton
  • 26,788
  • 9
  • 50
  • 60
  • How can you do the same with an external file-diff-merger? -- I run unsuccessfully in Mac % open -a filemerge Heee/master:.profile master:.profile – Léo Léopold Hertz 준영 May 27 '09 at 18:09
  • 1
    FileMerge.app doesn't accept input from stdin. You might have luck with this script that google produced: http://kerneltrap.org/mailarchive/git/2007/11/21/435536 – Jarret Hardie May 27 '09 at 18:14
  • 1
    You might also try Changes.app, which has a command line utility and can accept input from stdin... http://changesapp.com/ – Jarret Hardie May 27 '09 at 19:01
37

If you're currently checkout out to branchA, for example, you can use the command:

git diff branchB path/to/common/file/between/branches.txt

You can then edit the diff if you want a subset of the changes, or leave it as is, and git apply the diff as a patch. As for a GUI tool that does this, hopefully someone else will have a suggestion there.

Jarret Hardie
  • 95,172
  • 10
  • 132
  • 126
1

From the docs, you need something similar to the following in your .git/config file:

# Our diff algorithm
[diff]
    external = opendiff
Hank Gay
  • 70,339
  • 36
  • 160
  • 222