git difftool command
git difftoolThe command is used to view and compare file changes using an external diff tool.
git difftoolThis command is an extension of the git diff command, providing a more intuitive visual tool for resolving differences between files. It is suitable for users who prefer using graphical tools over command-line tools to handle file differences.
Basic Syntax
git difftool [<options>] [<commit> [<path>...]]
<commit>Specify the commit(s) to compare, defaulting to the current working directory state.<path>Specify the file path to compare.
Common options and usage:
| Options | Description | UsageExample |
|---|---|---|
--tool=<tool> | Specify the external diff tool to use. By default, Git uses the configured default diff tool. | git difftool --tool=meld |
--tool-help | Display the list of available diff tools. | git difftool --tool-help |
--dir-diff | Compare in directories rather than file by file. | git difftool --dir-diff |
--no-prompt | Skip the confirmation prompt for each file and automatically use the tool to view the differences. | git difftool --no-prompt |
--staged | Compare the differences between staged changes and the previous commit. | git difftool --staged |
--cached | and--stagedSame as above, used to compare the differences between cached changes and the previous commit. | git difftool --cached |
--merge | Used for merge tools to view differences when handling conflicts. | git difftool --merge |
--find-copies | Find file copy and move. | git difftool --find-copies |
--find-copies-harder | More strictly find file copy and move. | git difftool --find-copies-harder |
Common usage
1. View differences between the working directory and the most recent commit
Use the default diff tool to view the differences between changes in the current working directory and the most recent commit:
git difftool
2. View the differences between the staging area and the most recent commit
Use the default diff tool to view the differences between the changes in the staging area and the most recent commit:
git difftool --staged
3. View differences for a specific file
Use the default diff tool to view the changes of a specified file:
git difftool <file>
Example:
git difftool index.html
4. View differences using a specified tool
Use the meld tool to view differences (requires setting meld as the diff tool in Git configuration):
git difftool --tool=meld
5. View differences in the directory.
View changes in a directory rather than file by file:
git difftool --dir-diff
6. Skip the confirmation prompt
Automatically open the tool to view the differences of all files without confirmation:
git difftool --no-prompt
Configure an external diff tool
You can set the external diff tool in Git configuration. The following is an example of configuring the meld tool:
git config --global diff.tool meld git config --global difftool.meld.cmd 'meld "$BASE" "$LOCAL" "$REMOTE" --diff "$MERGED"'
You can configure other tools as needed (such as kdiff3, vimdiff, opendiff, etc.), and the specific configuration method depends on the command-line interface of the tool itself.
other extensions