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?
Git – How to view ‘git diff’ output with the preferred diff tool/ viewer
diff()diffmergedifftoolgitgit-difftool
Related Topic
- Git – How to undo the most recent local commits in Git
- Git: How to force “git pull” to overwrite local files
- Git – How to create a remote Git branch
- Git – How to check out a remote Git branch
- Git – How to delete a Git branch locally and remotely
- Git – How to push a new local branch to a remote Git repository and track it too
- Git – How to revert a Git repository to a previous commit
- Git – How to rename a local Git branch
Best Answer
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 '
| cat
' is needed only for some programs which may not return a proper or consistent return status. You might want to try without the trailing cat if your diff tool has explicit return status)(Diomidis Spinellis adds in the comments:
That (the article quoted above) is the theory for external tool defined through config file (not through environment variable).
In practice (still for config file definition of external tool), you can refer to: