Rust 编写的终端 Git 差异查看器 dffy 支持超大仓库
dffy 是一款用 Rust 编写的终端 Git 差异查看器,面向 Linux 内核级别的超大仓库设计。它不预先计算完整 diff,而是先渲染已发现的文件并在后台处理剩余部分,使 13000 个文件的变更也能快速打开。支持文件树、分屏或统一视图、单键操作,并提供 Homebrew 与脚本安装方式。
报道正文
本文目录6 个章节
dffy
A terminal diff viewer for git, written in Rust.
Built for large repositories, up to the size of the Linux kernel.
dffy # everything you haven't committed
dffy main..HEAD # any revision git understandsInstall
brew install --cask amalucelli/tap/dffy
# or
curl -fsSL https://raw.githubusercontent.com/amalucelli/dffy/main/install.sh | sh
# plus the experimental Markdown renderer: … | sh -s -- --plugin markdowndocs/install.md covers mise, building from source and the renderer plugins. Then try it in any repository: dffy HEAD~10.
About
dffy is a diff viewer for the terminal. Run it in a git repository and it opens a full-screen view of your changes: a file tree on the left, the diff on the right, split or unified. Pipe it, and it prints the diff instead.
It's built for big diffs. Instead of computing the whole diff up front, dffy shows the first files as soon as it finds them and works on the rest in the background, so a 13,000-file change opens as fast as a one-line fix.
It fits into how you already work. Every action is a single key, the layout adapts from a wide monitor down to a phone over SSH, and dffy can stand in for git's pager, git add -p filter and difftool. Settings live in a plain config file you can keep with your dotfiles.
Why dffy
dffy builds on tools I like: the terminal review flow of lumen, the review UX of hunk, and the rendering of diffs.com (Pierre's @pierre/diffs). None of them fit how I work. lumen centers on AI features I didn't want in a diff viewer. hunk is TypeScript on a JavaScript runtime, and I wanted a single native binary that stays fast on huge repos. diffs.com runs in the browser. So I built a native terminal diff viewer that works the same on a laptop and over SSH from a phone.
Features
Fast
- ⚡ Opens the Linux v6.0..v6.1 diff in 9.5ms and loads the rest in the background.
- 👀
--watchrepaints as you edit, stage and commit.
Reading diffs
- 🪟 Split or unified, picked by terminal width.
- 🌈 Syntax highlighting for 18 languages, with changed words emphasized.
- 🌳 A syntax-aware diff (
d) that marks reformatted (~) and moved (») code. - 🔁 Renames detected the way git detects them.
Navigation
- 🗂️ A file tree, a fuzzy file picker and search across the diff.
- 🎯 Each file opens at its first change, and
n/Njump between changes. - ⌨️ Single-key actions, with a command panel on
space.
Git
- 🧾 Staged, unstaged and untracked changes in one view, or any revision.
- 📟 Works as git's pager,
git add -pfilter and difftool. - 📁 Compares files and folders outside a repository too.
Anywhere
- 📱 Works on phones over SSH, with plain-letter keys and a frameless layout.
- 🖱️ Mouse selection that copies over SSH.
- 🎨 16 themes and a config file for your dotfiles.
- 🧩 Renderer plugins (experimental), such as Markdown diffed as rendered text.
Usage
dffy # staged, unstaged and untracked changes
dffy --staged # what's staged (git diff --cached)
dffy HEAD~3 # a revision against the working tree
dffy main...feature # changes since the merge base
dffy show HEAD # a commit with its message
dffy main.. -- src/ # limited to paths
dffy a.txt b.txt # two files or folders, no repository needed
dffy --watch # refresh on every change
dffy --syntax v6.0 v6.1 # diff by syntax
dffy --stat main.. # also --name-only, --name-status, --exit-codeWith git:
git config --global core.pager dffy
git config --global interactive.diffFilter "dffy --color-only"In the viewer, n/N move between changes, f/F between files, / searches, o finds a file, space lists commands and q quits. ~/.config/dffy/config holds key = value lines; dffy config --default lists every key with its default.
Comparison
dffy | hunk | lumen | difftastic | delta | diff-so-fancy | diff | |
|---|---|---|---|---|---|---|---|
| Interactive viewer with a file tree | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Watch mode | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| git's pager (reads a diff on stdin) | ✅ | ✅ | ❌ | ❌ | ✅ | ✅ | ❌ |
git add -p filter | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ |
| Syntax highlighting | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| Changed-word emphasis | ✅ | ✅ | ✅ | ✅ | ✅ | 🟡 | ❌ |
| Syntax-aware diff | ✅ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ |
| Split and unified, picked by width | ✅ | ✅ | ❌ | 🟡 | 🟡 | ❌ | 🟡 |
| Mouse | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| Compares files outside a repository | ✅ | 🟡 | ❌ | ✅ | ✅ | 🟡 | ✅ |
| Plugins or extensions | 🟡 | 🟡 | ❌ | ❌ | ❌ | ❌ | ❌ |
| Single native binary | ✅ | 🟡 | ✅ | ✅ | ✅ | ❌ | ✅ |
| AI or agent annotations | ❌ | ✅ | 🟡 | ❌ | ❌ | ❌ | ❌ |
| Other VCSs (Jujutsu, Mercurial, Sapling) | ❌ | ✅ | ✅ | ✅ | ✅ | 🟡 | — |
🟡 means partial support; docs/benchmarks.md explains each one. All seven are open source. GNU diff is GPL-3.0-or-later and the rest are MIT. Checked against hunk 0.25.0, lumen 2.32.0, difftastic 0.72.0, delta 0.20.1, diff-so-fancy 1.4.14 and GNU diffutils 3.10; docs/benchmarks.md links the source for every cell.
(注:更多技术实现细节与完整 API 文档请查阅原项目 README)