LinuxCommandLibrary

git-difftool

Compare files using external diff tools

TLDR

List available diff tools

$ git difftool --tool-help
copy

Set the default diff tool to meld
$ git config --global diff.tool "[meld]"
copy

Use the default diff tool to show staged changes
$ git difftool --staged
copy

Use a specific tool (opendiff) to show changes since a given commit
$ git difftool [[-t|--tool]] [opendiff] [commit]
copy

SYNOPSIS

git difftool [] [ []] [--] [...]

PARAMETERS

-t | --tool=
    Use the specified diff tool. Valid values are tool names.

-y | --no-prompt
    Do not prompt before launching each diff tool.

-d | --dir-diff
    Perform a directory diff.

-g | --gui
    Launch the specified diff tool in GUI mode if it supports it.

--ext-cmd=
    Execute the given command instead of using a diff tool.

--[no-]symlinks
    Follow symbolic links.


    Specify the commits to compare.

[--] [...]
    Limit the diff to the specified paths.

-x | --extcmd=
    Specify a custom command for external diff tool. Deprecated, use --ext-cmd.

-O
    Order files according to the specified orderfile.

DESCRIPTION

The git-difftool command is a powerful tool that allows you to use graphical diff viewers to compare changes between revisions, branches, or working tree files in a Git repository. Instead of relying solely on the command-line diff output, git-difftool launches a visual comparison tool, making it easier to identify and understand the differences between files. It supports a variety of diff tools, including common options like meld, kdiff3, vimdiff, and many others.

By default, git-difftool compares the working tree version of a file with the index. You can specify different revisions or branches to compare using command-line options. This command simplifies the process of reviewing code changes, resolving merge conflicts, and understanding the history of your files. It is particularly useful when dealing with large files or complex changesets where the command-line diff output can be overwhelming. You can easily configure a preferred diff tool, allowing for seamless integration into your Git workflow.

CONFIGURATION

The git difftool command relies on configuration options to determine which diff tool to use and how it should be launched. You can set the default diff tool using the diff.tool configuration variable. You can also configure tool-specific settings, such as command-line arguments or GUI preferences, using the difftool.<tool>.cmd and difftool.<tool>.trustExitCode configuration variables.

CUSTOM TOOLS

You can define custom diff tools by specifying their names and commands in the Git configuration. This allows you to integrate specialized diff tools or scripts that are not directly supported by Git. The command must take two arguments which represent the files to compare.

SEE ALSO

git diff(1), git mergetool(1), git config(1)

Copied to clipboard