When I type git diff, I’d like to see a side-by-side diff, like with diff -y, or like to display the diff in an interactive diff tool like kdiff3. How can this be done?
When I type git diff , I’d like to see a side-by-side diff, like
Share
Although Git has an internal implementation of diff, you can set up an external tool instead.
There are two different ways to specify an external diff tool:
GIT_EXTERNAL_DIFFand theGIT_DIFF_OPTSenvironment variables.git configymattw‘s answer is also pretty neat, usingydiffSee also:
git diff --helpWhen doing a
git diff, Git checks both the settings of above environment variables and its.gitconfigfile.By default, Git passes the following seven arguments to the diff program:
You typically only need the old-file and new-file parameters. Of course most diff tools only take two file names as an argument. This means that you need to write a small wrapper-script, which takes the arguments which Git provides to the script, and hands them on to the external git program of your choice.
Let’s say you put your wrapper-script under
~/scripts/my_diff.sh:you then need to make that script executable:
you then need to tell Git how and where to find your custom diff wrapper script.
You have three choices how to do that: (I prefer editing the .gitconfig file)
Using
GIT_EXTERNAL_DIFF,GIT_DIFF_OPTSe.g. in your .bashrc or .bash_profile file you can set:
Using
git configuse "git config" to define where your wrapper script can be found:
Editing your
~/.gitconfigfileyou can edit your
~/.gitconfigfile to add these lines:Note:
Similarly to installing your custom diff tool, you can also install a custom merge-tool, which could be a visual merging tool to better help visualizing the merge. (see the progit.org page)
See: http://fredpalma.com/518/visual-diff-and-merge-tool/ and https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration