Skip to content

difftool Git Command Guide

The git difftool command is used to show changes using common diff tools. It is a frontend to git diff and allows you to compare and edit files between revisions using GUI or terminal-based diff tools.

Terminal window
git difftool [<options>] [<commit> [<commit>]] [--] [<path>...]
OptionDescription
-d, —dir-diffCopy files to temp location for directory diff
-y, —no-promptDo not prompt before launching diff tool
—promptPrompt before each invocation (default)
-t , —tool=Use specified tool (meld, vimdiff, etc.)
—tool-helpPrint list of available diff tools
—[no-]symlinksCreate symlinks or copies in dir-diff mode
-x , —extcmd=Use custom command for diffs
-g, —[no-]guiUse GUI diff tool instead of regular one
—[no-]trust-exit-codeHandle diff tool exit codes
—rotate-to=Start diff at specified file, rotate others
—skip-to=Start diff at specified file, skip others
ParameterDescription
[]First commit to compare (default: HEAD)
[]Second commit to compare (default: working tree)
[…]Optional file paths to limit comparison
Terminal window
git difftool HEAD~1

Launches default diff tool to compare working tree with HEAD~1.

Terminal window
git difftool -t meld HEAD

Uses meld to compare working tree with HEAD.

Terminal window
git difftool -d HEAD

Copies modified files to temp directory and performs directory diff.

Terminal window
git difftool -y HEAD~1 HEAD

Launches diff tool without prompting for each file.

Terminal window
git difftool HEAD~2 HEAD~1

Shows differences between HEAD2 and HEAD1 using diff tool.

Terminal window
git difftool --skip-to=src/main.java HEAD

Starts diff from specific file, skipping those before it.

How do I launch a diff tool for unstaged changes?

Section titled “How do I launch a diff tool for unstaged changes?”

To launch a diff tool for unstaged changes, run:

Terminal window
git difftool

To specify a diff tool, use the -t option:

Terminal window
git difftool -t <toolname>

To perform a directory diff, use the -d option:

Terminal window
git difftool -d HEAD

To see available diff tools, execute:

Terminal window
git difftool --tool-help

To use a custom command, use the -x option:

Terminal window
git difftool -x 'vimdiff $LOCAL $REMOTE'

To make GUI the default, run:

Terminal window
git config difftool.guiDefault true
  1. Visual code review with GUI diff tools
  2. Comparing files between commits with external tools
  3. Resolving merge conflicts interactively
  4. Analyzing changes with specialized diff viewers
  5. Improving productivity when reviewing code changes