Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

git difftool Command

git difftool Command

Git Basic OperationsGit Basic Operations


git difftool The command is used to view and compare file changes using an external diff tool.

git difftool The command is an extension of the git diff command, providing a more intuitive visual tool to resolve differences between files. It is suitable for users who prefer to use graphical tools rather than command-line tools to handle file differences.

Basic Syntax



git difftool [] [ [...]]

Common options and usage:

Option Description Usage Examples
--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 a directory 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 last commit. git difftool --staged
--cached The difference between --staged Same, used to compare staged changes with the last commit. git difftool --cached
--merge Used by merge tools to view differences when handling conflicts. git difftool --merge
--find-copies Find file copies and moves. git difftool --find-copies
--find-copies-harder Find file copies and moves more strictly. git difftool --find-copies-harder

Common usage

1. View the 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 changes in the staging area and the most recent commit:



git difftool --staged

3. View the differences of a specific file

Use the default diff tool to view the changes of a specified file:



git difftool 

Example:



git difftool index.html

4. View differences using a specified tool

Use the meld tool to view differences (you need to set meld as the diff tool in the Git configuration):



git difftool --tool=meld

5. View differences in a 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 an external diff tool in the 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 (such as kdiff3, vimdiff, opendiff, etc.) as needed; the specific configuration method depends on the tool's own command-line interface.


Git Basic OperationsGit Basic Operations