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.
git difftool Syntax:
Section titled “git difftool Syntax:”git difftool [<options>] [<commit> [<commit>]] [--] [<path>...]Options:
Section titled “Options:”| Option | Description |
|---|---|
| -d, —dir-diff | Copy files to temp location for directory diff |
| -y, —no-prompt | Do not prompt before launching diff tool |
| —prompt | Prompt before each invocation (default) |
| -t | Use specified tool (meld, vimdiff, etc.) |
| —tool-help | Print list of available diff tools |
| —[no-]symlinks | Create symlinks or copies in dir-diff mode |
| -x | Use custom command for diffs |
| -g, —[no-]gui | Use GUI diff tool instead of regular one |
| —[no-]trust-exit-code | Handle diff tool exit codes |
| —rotate-to= | Start diff at specified file, rotate others |
| —skip-to= | Start diff at specified file, skip others |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
| [ | First commit to compare (default: HEAD) |
| [ | Second commit to compare (default: working tree) |
| [ | Optional file paths to limit comparison |
git difftool Command Samples:
Section titled “git difftool Command Samples:”View differences with default tool
Section titled “View differences with default tool”git difftool HEAD~1Launches default diff tool to compare working tree with HEAD~1.
Use specific diff tool
Section titled “Use specific diff tool”git difftool -t meld HEADUses meld to compare working tree with HEAD.
Directory diff mode
Section titled “Directory diff mode”git difftool -d HEADCopies modified files to temp directory and performs directory diff.
No prompt mode
Section titled “No prompt mode”git difftool -y HEAD~1 HEADLaunches diff tool without prompting for each file.
Compare two commits
Section titled “Compare two commits”git difftool HEAD~2 HEAD~1Shows differences between HEAD2 and HEAD1 using diff tool.
Skip to specific file
Section titled “Skip to specific file”git difftool --skip-to=src/main.java HEADStarts 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:
git difftoolHow can I specify which diff tool to use?
Section titled “How can I specify which diff tool to use?”To specify a diff tool, use the -t option:
git difftool -t <toolname>How do I perform a directory diff?
Section titled “How do I perform a directory diff?”To perform a directory diff, use the -d option:
git difftool -d HEADHow can I see available diff tools?
Section titled “How can I see available diff tools?”To see available diff tools, execute:
git difftool --tool-helpHow do I use a custom diff command?
Section titled “How do I use a custom diff command?”To use a custom command, use the -x option:
git difftool -x 'vimdiff $LOCAL $REMOTE'How can I make difftool GUI the default?
Section titled “How can I make difftool GUI the default?”To make GUI the default, run:
git config difftool.guiDefault trueApplications of the git difftool command
Section titled “Applications of the git difftool command”- Visual code review with GUI diff tools
- Comparing files between commits with external tools
- Resolving merge conflicts interactively
- Analyzing changes with specialized diff viewers
- Improving productivity when reviewing code changes