difft
Compare differences between text files side-by-side
TLDR
Compare two files or directories
Only report the presence of differences between the files
Specify the display mode (default is side-by-side)
Ignore comments when comparing
Enable/Disable syntax highlighting of source code (default is on)
Do not output anything at all if there are no differences between files
Print all programming languages supported by the tool, along with their extensions
SYNOPSIS
difft [OPTIONS] <FILE1> <FILE2>
difft [OPTIONS] -- <DIR1> <DIR2>
PARAMETERS
--color {always,auto,never}
Control when to use ANSI colors in the output.
--display {inline,side-by-side}
Choose between inline diff or side-by-side column view.
--syntax-highlight {auto,always,never}
Enable or disable syntax highlighting for file content.
--lang {language}
Force a specific language parser for the input files.
--line-numbers {auto,always,never}
Display line numbers next to diffed content.
--tab-width {width}
Set the number of spaces for a tab character.
--context {lines}
Number of unchanged lines to show around changes (default: 3).
--diff-context {lines}
Similar to --context, but for the diff algorithm itself.
--show-skipped-lines
Show lines that difftastic skipped due to parsing errors.
--byte-changes
Fall back to byte-level diff for lines with syntax errors.
-h, --help
Display help message and exit.
-V, --version
Display version information and exit.
DESCRIPTION
difft (short for difftastic) is a command-line tool that performs semantic, structural diffs on files, contrasting with traditional line-based diff utilities like diff. Instead of just comparing lines, difft parses files into their underlying syntax tree, identifying changes at the token, statement, or expression level. This approach results in more accurate and readable diffs, especially for code, as it can highlight moving blocks of code, renamed variables, or reordered parameters, rather than just showing entire lines as added or removed. It supports over 50 programming languages and various text formats, providing syntax highlighting and configurable output styles (inline or side-by-side).
CAVEATS
difft is a third-party tool and not part of standard Linux distributions by default, requiring separate installation. While highly effective for code, its structural parsing can sometimes be slower than traditional line-based diffs for very large files. Its output, while clearer for semantic changes, may be more verbose than diff for trivial differences or non-code text. It's primarily designed for human readability, making it less suitable for scripting or automated parsing compared to diff's more rigid output format.
INSTALLATION
As difft is not a standard utility, it must be installed. Common methods include: using Cargo (Rust's package manager) with cargo install difftastic; via Homebrew (macOS/Linux) with brew install difftastic; or from pre-built binaries or package managers specific to your distribution.
GIT INTEGRATION
difft can be configured as Git's default diff tool for a superior code review experience. This is typically done by configuring Git to use difft by setting core.pager to 'difft --patience --display=inline --syntax-highlight=auto' and diff.external to difft globally.
HISTORY
difftastic was created by Wilfred Hughes, with its first public release appearing around 2021. It emerged as a response to the limitations of traditional line-based diff algorithms, which often produce noisy or misleading output for code changes. Its development focused on leveraging modern parsing techniques (specifically tree-sitter) to understand the structure of code, providing a more intelligent and developer-friendly way to visualize changes. It quickly gained popularity in the developer community for its innovative approach.