Git Reference ยท Inspecting History
git difftool command
Reference for git difftool: compare files in a graphical or custom diff program, choose a tool with --tool, use --dir-diff, and configure difftool.<tool>.cmd.
git difftool takes the same arguments as git diff, but instead of printing a patch it starts an external program once per changed file and hands it two temporary files: the old version and the new version. Typical programs are Meld, Beyond Compare, vimdiff, KDiff3 and the diff view of an editor such as VS Code.
It is a front end only. What changes is selected exactly as with git diff: working tree against index, --cached, two commits, a range, and path limits.
git difftool [<diff-options>] [<commit> [<commit>]] [-- <path>...] git difftool --tool=<tool> | -t <tool> | -x <command> git difftool --dir-diff | -d
Try it
Graphical tools cannot run on our server, so the examples use a small custom command that prints a line per file. On your computer you would configure a real viewer instead.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
| Option | Description |
|---|---|
-t <tool>, --tool=<tool> |
Use a built-in or configured tool. --tool-help lists the tools Git knows and which are installed. |
-x <cmd>, --extcmd=<cmd> |
Run an arbitrary command; Git appends the two file names. |
-y, --no-prompt |
Do not ask "Viewing (1/3): 'file'. Launch tool?" before every file. -y is the short form; --prompt restores the question. |
-d, --dir-diff |
Copy both sides into two temporary directories and start the tool once on the directories. |
--symlinks, --no-symlinks |
In directory mode, link unchanged working tree files instead of copying them. |
--trust-exit-code |
Stop and fail when the tool exits non-zero. By default Git ignores the status. |
-g, --gui |
Use diff.guitool instead of diff.tool. |
Configuration: diff.tool (default tool), diff.guitool, difftool.<tool>.cmd (a shell command), difftool.<tool>.path (location of a built-in tool's executable), difftool.prompt and difftool.trustExitCode. In the command, these variables are available: $LOCAL (the old side), $REMOTE (the new side), $MERGED (the file name in the working tree) and $BASE.
Usage notes
- One file at a time is the default: close the viewer to see the next file. Directory mode shows the whole change set in one window and suits tools that have a tree view.
- Files that differ only by mode, or binary files, are still passed to the tool.
- Without any tool configured, Git picks a likely installed one, so run
git difftool --tool-helponce and then setdiff.toolexplicitly. - Do not confuse it with git mergetool, which resolves conflicts and writes a result.
- For one-off use of an external viewer without the difftool wrapper,
GIT_EXTERNAL_DIFFordiff.externalalso works, but it receives seven arguments instead of two files.
Related
- git diff, git mergetool, diff options, git config
- Tutorial: Diff and compare, Merge conflicts