目录导航
介绍
Difftastic 是一个实验性的差异工具,可以根据文件的语法比较文件的不同之处并进行高亮显示.
difftastic支持以下语言:
Bash
C
C++
C#
Clojure
Common Lisp
CSS
Dart
Elixir
Emacs Lisp
Gleam
Go
Haskell
Janet
Java
JavaScript (and JSX)
JSON
Lua
Nix
OCaml
PHP
Python
Ruby
Rust
Scala
TypeScript (and TSX)
YAML
Zig
difftastic安装方法
二进制安装

- difft-x86_64-apple-darwin.tar.gz3.53 MB
- difft-x86_64-pc-windows-msvc.zip3.4 MB
- difft-x86_64-unknown-linux-gnu.tar.gz 3.67 MB
从源安装
构建要求
Difftastic 是用 Rust 编写的,所以你需要安装 Rust。我推荐rustup来安装 Rust。Difftastic 需要 Rust 1.56 或更高版本。
您还需要一个支持 C++14 的 C++ 编译器。如果您使用的是 GCC,则至少需要版本 8。
构建
您可以使用 Cargo(它是 Rust 的一部分)在 crates.io 上下载和构建 difftastic 。
cargo install difftastic
Difftastic 使用cc
crate 来构建 C/C++ 依赖项。这允许您使用环境变量CC
并CXX
控制使用的编译器(请参阅cc 文档)。
用法
文件差异对比
difft sample_files/before.js sample_files/after.js
Difftastic 使用文件扩展名来决定使用哪个解析器。
不同的目录
difft sample_files/dir_before/ sample_files/dir_after/
Difftastic 将递归遍历这两个目录,区分具有相同名称的文件。
语言检测
Difftastic 根据文件扩展名、文件名和第一行的内容猜测使用的语言。
--language
您可以通过传递选项来覆盖语言检测。Difftastic 会将输入文件视为具有该扩展名,并忽略其他语言检测启发式。
difft --language cpp before.c after.c
git
Git支持外部差异工具。您可以使用GIT_EXTERNAL_DIFF
一次性 git 命令。
$ GIT_EXTERNAL_DIFF=difft git diff
$ GIT_EXTERNAL_DIFF=difft git log -p --ext-diff
$ GIT_EXTERNAL_DIFF=difft git show e96a7241760319 --ext-diff
如果您想默认使用 difftastic,请使用git config
.
# Set git configuration for the current repository.
$ git config diff.external difft
# Set git configuration for all repositories.
$ git config --global diff.external difft
运行后git config
,git diff
会difft
自动使用。其他 git 命令需要--ext-diff
使用 diff.external
.
$ git diff
$ git log -p --ext-diff
$ git show e96a7241760319 --ext-diff
git-difftool
git difftool是一个 git 命令,用于使用不同的 diff 工具查看当前更改。如果您想偶尔使用 difftastic,这很有用。
添加以下内容以.gitconfig
使用 difftastic 作为您的 difftool。
[diff]
tool = difftastic
[difftool]
prompt = false
[difftool "difftastic"]
cmd = difft "$LOCAL" "$REMOTE"
然后,您可以运行git difftool
以查看当前更改与 difftastic。
$ git difftool
我们还推荐以下设置以获得最佳 difftool 体验。
# Use a pager for large output, just like other git commands.
[pager]
difftool = true
# `git dft` is less to type than `git difftool`.
[alias]
dft = difftool
使用示例
项目地址
GitHub:https://github.com/Wilfred/difftastic
转载请注明出处及链接