git-difftool
Compare files using external diff tools
TLDR
List available diff tools
Set the default diff tool to meld
Use the default diff tool to show staged changes
Use a specific tool (opendiff) to show changes since a given commit
SYNOPSIS
git difftool [options] [commit [commit]] [--] [path...]
PARAMETERS
-t
Specify the graphical diff tool to use (e.g., meld, kdiff3, vscode). This option overrides the diff.tool configuration.
--tool-help
Display a list of all available and configured diff tools that git-difftool recognizes.
--dir-diff
Compare files by directly showing two directories to the diff tool instead of opening individual files. The external tool must support directory comparison for this to work.
--no-prompt
Do not prompt before launching each diff tool. The tool will be launched automatically for all changed files without user interaction.
--prompt
Prompt before launching each diff tool. This is the default behavior when multiple files are involved, allowing users to skip or continue to the next file.
--extcmd=
Use an external command for comparison instead of a configured tool. The command receives seven arguments representing different versions of the file and its status.
--cached, --staged
Compare the changes between the index (staged changes) and the HEAD commit. This is equivalent to git difftool HEAD.
--no-index
Compare two arbitrary files on the filesystem. Requires exactly two file paths as arguments after this option.
Specify one or two commits to compare. If one commit is given, it compares the working tree with that commit. If two commits are given, it compares the content between the two commits.
[--]
Limit the diff to specific files or directories. The double dash (--) is used to separate options from path arguments, especially if paths might conflict with options.
DESCRIPTION
The git-difftool command allows users to visually inspect differences between Git revisions using a preferred external graphical diff viewer. Unlike git diff, which outputs changes directly to the terminal, git-difftool launches an application like Meld, KDiff3, Beyond Compare, or VS Code to display the file changes in a user-friendly graphical interface.
It can be used to compare the working tree with the index, a specific commit, or between two arbitrary commits. When multiple files have changes, git-difftool will open each modified file sequentially in the configured diff viewer, often prompting the user to continue to the next file or exit. This makes it invaluable for detailed code reviews, understanding complex changes, or resolving discrepancies visually.
CAVEATS
git-difftool requires an external diff viewer application to be installed and correctly configured on your system. Without a properly configured tool, the command will either fail or prompt you to install and configure one. Configuration typically involves setting diff.tool and optionally difftool.
CONFIGURATION
To use git-difftool effectively, you need to configure your preferred diff tool. This is typically done using git config:
Set the default tool globally:
git config --global diff.tool meld
If Git cannot find your tool automatically, you might need to specify its full path:
git config --global difftool.meld.path /usr/bin/meld
You can also configure whether to prompt for each file globally:
git config --global difftool.prompt false
These configurations can be set per repository, globally, or for the current user depending on the --local, --global, or --system options of git config.
HISTORY
Introduced early in Git's development, git-difftool evolved to provide a more intuitive and visual way to inspect changes, complementing the command-line output of git diff. Its integration with a wide range of third-party diff applications solidified its role as a key utility for developers preferring graphical interfaces for code comparison, enhancing Git's usability for detailed review tasks.
SEE ALSO
git diff(1), git config(1), git mergetool(1)