- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git-difftool Tutorial
Use an external graphical tool to view diffs, improving code review and conflict comprehension efficiency.
- A basic mental model of worktree, index, and commits
- Comfort reading `git status` and a small commit graph
- Using local cleanup commands on already shared history
- Continuing to rewrite before confirming a recovery path
The short version
git-difftool invokes your configured external graphical diff tool to view differences between the working tree, the index, or commits — more intuitive than command-line git diff.
When it is a good fit
- When you need to visualize diffs across many files
- When you want to leverage your IDE's diff view for more intuitive code review
- When command-line diff output is too long to quickly locate key changes
Basic example
# Use the default configured diff tool to view working tree vs index
git difftool
# View index vs latest commit
git difftool --staged
# View diff between two commits
git difftool HEAD~3 HEAD
# Use difftool on a specific file
git difftool src/app.js
# Use a specific tool (even if it's not the default)
git difftool --tool=vimdiff
# List all available diff tools
git difftool --tool-help
What to watch most closely
difftool's behavior depends entirely on your configured external tool. Different tools (VS Code, Beyond Compare, Kaleidoscope) have very different launch behaviors and interaction experiences. Make sure your team members understand which tool your project uses.
A safer working habit
Standardize the team's default difftool configuration and document it in the project README or onboarding docs. This ensures everyone has a consistent experience when reviewing diffs, and makes it easier to reference specific changes during code review discussions.
Useful angles for understanding it
- Configure the default tool:
git config --global diff.tool vscode - Configure a tool's path:
git config --global difftool.vscode.cmd 'code --wait --diff $LOCAL $REMOTE' --no-promptskips the confirmation prompt and opens the tool directly--dir-diffmode can compare entire directory trees (supported by some tools)git difftoolandgit mergetoolusually share the same tool ecosystem
What problem this command solves in a workflow
Command-line diff is efficient for simple changes, but when dealing with multiple files, complex refactors, or the need to pinpoint changes line-by-line, graphical diff tools with syntax highlighting, side-by-side comparison, and expand/collapse features significantly improve comprehension speed. difftool connects Git's diff computation with professional visualization tools.
Typical use cases
- Quickly browsing all file changes before reviewing a large PR
- Viewing the diff between both sides before resolving a merge conflict
- Comparing the full change set between two historical versions to understand code evolution
- Viewing differences for a specific file across branches
Diagram view
Special cases and boundaries
- If no default tool is configured,
git difftoolwill prompt you to select one - Some tools (e.g.,
vimdiff) run in the terminal; others (e.g.,vscode) require a GUI environment --trust-exit-codemakes difftool's exit code reflect the tool's own exit status- In CI/CD environments difftool is usually not suitable because there is no graphical interface
difftooldoes not modify any files; it is a read-only viewing tool
Related reading
Read it alongside git diff, git mergetool, and git log -p to understand the boundaries between command-line and graphical diff viewing.