← 返回命令列表

Linux command

difft 命令

文件

复制后可按需替换文件名、目录或参数。

常用示例

Compare two files

difft [old_file] [new_file]

Compare files with side-by-side output

difft --display side-by-side [old_file] [new_file]

Show only changed lines

difft --display inline [old_file] [new_file]

Compare with specific language

difft --language [rust] [old.rs] [new.rs]

Compare directories

difft [old_directory] [new_directory]

Use with git diff

git diff --external-diff difft

Set as default git diff tool

git config --global diff.external difft

Compare and skip unchanged sections

difft --skip-unchanged [old_file] [new_file]

说明

difft (Difftastic) is a structural diff tool that understands programming language syntax. Unlike line-based diff tools, it parses source code and compares the actual structure, showing meaningful changes while ignoring formatting differences. The tool builds abstract syntax trees (ASTs) for both versions of a file, then computes the minimal structural difference. This means it can recognize when code is moved or refactored without treating it as completely different, and it won't flag changes that are purely whitespace or formatting. Difftastic supports over 50 programming languages with dedicated parsers built using tree-sitter. For unsupported files, it falls back to a text-based diff. Language detection is automatic based on file extension, but can be overridden. The side-by-side display shows old and new versions in parallel columns with colors indicating additions (green), deletions (red), and modifications. The inline display shows changes in a more compact format. Git integration allows using difft as the external diff tool.

参数

--display _mode_
Output format: side-by-side, side-by-side-show-both, inline (default).
--language _lang_
Force a specific language parser (auto-detected by default).
--list-languages
Show all supported languages.
--skip-unchanged
Don't show unchanged parts of the file.
--context _n_
Number of context lines (default: 3).
--width _n_
Maximum display width (default: terminal width).
--color _when_
Color output: always, never, auto.
--background _type_
Background color: light, dark (default: dark).
--syntax-highlight _on|off_
Enable or disable syntax highlighting.
--tab-width _n_
Tab display width (default: 4).
--parse-error-limit _n_
Maximum number of parse errors before falling back to text diff.
--byte-limit _n_
Skip files larger than this size.
--graph-limit _n_
Maximum graph size for structural diff algorithm.
--exit-code
Set exit code to 1 if there are syntactic changes (useful in scripts).

FAQ

What is the difft command used for?

difft (Difftastic) is a structural diff tool that understands programming language syntax. Unlike line-based diff tools, it parses source code and compares the actual structure, showing meaningful changes while ignoring formatting differences. The tool builds abstract syntax trees (ASTs) for both versions of a file, then computes the minimal structural difference. This means it can recognize when code is moved or refactored without treating it as completely different, and it won't flag changes that are purely whitespace or formatting. Difftastic supports over 50 programming languages with dedicated parsers built using tree-sitter. For unsupported files, it falls back to a text-based diff. Language detection is automatic based on file extension, but can be overridden. The side-by-side display shows old and new versions in parallel columns with colors indicating additions (green), deletions (red), and modifications. The inline display shows changes in a more compact format. Git integration allows using difft as the external diff tool.

How do I run a basic difft example?

Run `difft [old_file] [new_file]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --display _mode_ do in difft?

Output format: side-by-side, side-by-side-show-both, inline (default).