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?
For 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, gitdiff
. Running this command temporarily redirects git diff
to use a visual diff program of your choice (as opposed to VonC's solution that does it permanently). This allows me to have both the default Git diff functionality (git diff
) as well as visual diff functionality (gitdiff
). Both commands take the same parameters, so for example to visually diff changes in a particular file you can type
gitdiff path/file.txt
Note that $GitInstall
is used as a placeholder for the directory where Git is installed.
Create a new file, $GitInstall\cmd\gitdiff.cmd
@echo off
setlocal
for /F "delims=" %%I in ("%~dp0..") do @set path=%%~fI\bin;%%~fI\mingw\bin;%PATH%
if "%HOME%"=="" @set HOME=%USERPROFILE%
set GIT_EXTERNAL_DIFF=git-diff-visual.cmd
set GIT_PAGER=cat
git diff %*
endlocal
Create a new file, $GitInstall\bin\git-diff-visual.cmd
(replacing [visual_diff_exe]
placeholder with full path to the diff program of your choice)
@echo off
rem diff is called by git with 7 parameters:
rem path old-file old-hex old-mode new-file new-hex new-mode
echo Diffing "%5"
"[visual_diff_exe]" "%2" "%5"
exit 0
You're now done. Running gitdiff
from within a Git repository should now invoke your visual diff program for every file that was changed.