When I type 'git diff', I want to view the output with my visual diff tool of choice (SourceGear diffmerge on Windows). How do I configure git to do this?
|
Since Git1.6.3, you can use the git difftool script: see my answer below. May be this article will help you. Here are the best parts: There are two different ways to specify an external diff tool. The first is the method you used, by setting the GIT_EXTERNAL_DIFF variable. However, the variable is supposed to point to the full path of the executable. Moreover, the executable specified by GIT_EXTERNAL_DIFF will be called with a fixed set of 7 arguments:
As most diff tools will require a different order (and only some) of the arguments, you will most likely have to specify a wrapper script instead, which in turn calls the real diff tool. The second method, which I prefer, is to configure the external diff tool via "git config". Here is what I did: 1) Create a wrapper script "git-diff-wrapper.sh" which contains something like
As you can see, only the second ("old-file") and fifth ("new-file") arguments will be passed to the diff tool. 2) Type
at the command prompt, replacing with the path to "git-diff-wrapper.sh", so your ~/.gitconfig contains
Be sure to use the correct syntax to specify the paths to the wrapper script and diff tool, i.e. use forward slashed instead of backslashes. In my case, I have
in .gitconfig and
in the wrapper script. Mind the trailing "cat"! (I suppose the ' That (the article quoted above) is the theory for external tool defined through config file (not through environment variable).
|
|||||||||||||||||||||
|
A short summary of the above great answers:
Then use it by typing (optionally specifying file name as well):
|
|||
|
If you happen to already have a diff tool associated with filetypes (say, because you installed TortoiseSVN which comes with a diff viewer) you could just pipe the regular
Setting it as a global alias works even better:
|
|||
|
you can use for example if you have meld, you can edit the branchs
|
|||
|
I tried the fancy stuff here (with tkdiff) and nothing worked for me. So I wrote the following script, tkgitdiff. It does what I need it to do.
|
|||||
|
I've been using this bit in
With
But now I got tired of always using meld in graphical environment, and it's not trivial to invoke the normal diff with this setup, so I switched to this:
With this setup, things like this work:
And I still get to keep the good old |
|||
|
Solution for Windows/msys gitAfter reading the answers, I discovered a simpler way that involves changing only one file.
Now when you type "git diff", it will invoke your external diff viewer. |
|||||||||||||||||
|
To complete my previous "diff.external" config answer above: As mentioned by Jakub, Git1.6.3 introduced git difftool, originally proposed in September 2008: USAGE=
The last use case is when you'd like to compare your current worktree to something other than HEAD (e.g. a tag)
Practical case for configuring difftool with your custom diff tool:
With winmerge.sh stored in a directory part of your PATH:
If you have another tool (kdiff3, P4Diff, ...), create another shell script, and the appropriate You have also this blog entry by Dave to add other details. The interest with this setting is the See for instance David Marble's answer below for an example which deals with:
As Kem Mason mentions in his answer, you can also avoid any wrapper by using the
For instance, this is how |
|||||||||||||||||||||
|
this works for me on windows 7. No need for intermediary sh scripts contents of .gitconfig:
|
|||||||||
|
Since git version 1.6.3 there is "git difftool" which you can configure to use your favorite graphical diff tool. Currently supported out-of-the-box are kdiff3, kompare, tkdiff, meld, xxdiff, emerge, vimdiff, gvimdiff, ecmerge, diffuse and opendiff; if the tool you want to use isn't on this list, you can always use ' "git difftool" accepts the same options as "git diff". |
|||||||||||||
|
If you're on a Mac and have XCode, then you have FileMerge installed. The terminal command is opendiff, so you can just do |
|||||
|
One addition to this. I like to regularly use a diff app that isn't support as one of the default tools via
I also like to have the default You can use an arbitrary
It just passes the 2 files to the command you specify, so you probably don't need a wrapper either. |
|||||
|
Building on VonC's answer to deal with file removals and additions, use the following commands and scripts:
Which is the same as putting this in your global
Then put the following in
|
|||||||||||||
|
You may want to try out xd http://github.com/jiqingtang/xd, which is GUI wrapper for GIT/SVN diff. It is NOT a diff tool itself. You run "xd" when you want to run "git diff" or "svn diff" and it will show you a list of files, a preview window and you can launch any diff tool you like, including tkdiff, xxdiff, gvimdiff, emacs(ediff), xemacs(ediff), meld, diffuse, kompare and kdiff3. You can also run any custom tool. Unfortunately the tool doesn't support Windows. |
|||||
|
If you're doing this through cygwin, you may need to use cygpath:
|
|||||||||
|
In the spirit of answering questions that are somewhat different than asked. Try this solution:
Meld understands git and provides navigating around the recent changes. |
|||||||||||||||||||||
|
I use kompare on ubuntu:
To compare two branches:
|
|||
|
For a linux version of how to configure a diff tool on git versions prior to 1.6.3 (1.6.3 added difftool to git) this is a great concise tutorial, in brief: Step 1: add this to your .gitconfig
Step 2: create a file named git_diff_wrapper, put it somewhere in your $PATH
|
|||
|
With new git difftool, its as simple as adding this to your .gitconfig file:
Also check out diffall, a simple script I wrote to extend the annoying (IMO) default diff behaviour of opening each in serial. |
|||||||||||||||||
|
Here's a batch file that works for Windows - assumes DiffMerge installed in default location, handles x64, handles forward to backslash replacement as necessary and has ability to install itself. Should be easy to replace DiffMerge with your favourite diff program. To install:
gitvdiff.bat:
|
|||||||||
|
IntroductionFor reference I'd like to include my variation on VonC's answer. Keep in mind that I am using the MSys version of Git (1.6.0.2 at this time) with modified PATH, and running Git itself from Powershell (or cmd.exe), not the Bash shell. I introduced a new command,
SetupNote that
|
|||
|