OmniDiff 开源 Rust Git 差异工具 支持内容感知对比

原标题:Show HN: OmniDiff – Opensource, super fast, content aware Git difftool, in Rust
68AI 研判分

开发者发布开源 Rust 工具 OmniDiff,旨在提供快速且具备内容感知能力的 Git 差异对比。该工具声称能处理 99.95% 的代码变更,并针对代码、图片、PDF 等多种文件类型优化了算法精度与速度,目前处于 v0.3.0 早期阶段但已具备日常可用性。

报道正文

本文目录9 个章节

OmniDiff

Fast, robust, accurate content-aware diffing.

  • Robust: can diff 99.95% of code changes
  • Content-aware: 98.8% of changes diffed using content-specific algorithms
ContentFast: under 100msAccurate: perfectAccurate: near-perfect
Code98%70%92%
Pictures96%69%91%
Cursors100%85%100%
Fonts95%82%100%
Archives88%87%87%
Message catalogs100%83%83%
PDFs57%100%100%

Speed measured on a T14s, Intel Core i7-1370P with 32 GB RAM (see Fast). PDFs have fewer than ten judged test cases (see Accurate).

See it in the browser: twenty real code changes, recorded from the command-line tool and compared side by side in Unix diff and in OmniDiff, and content examples: an OpenDocument file, a compiled translation catalog, and pictures, still and animated.

An animation of one Python refactoring painted two ways. A vertical bar sweeps left to right and
back across a two-pane diff. On one side of the bar, GNU diff marks whole lines as deleted and
inserted; on the other, OmniDiff paints only the parts that changed - sum(numbers) and
len(numbers) rather than the whole assignment, and numbers shown as moved rather than
rewritten.

Various light and dark themes are available:

A screenshot of OmniDiff's two-panel terminal UI in a light theme, showing the same Python
refactoring, with the changed right-hand sides highlighted rather than whole
lines

Files are diffed based on type. A PDF diagram with one box renamed, and a web font with twenty icons redrawn:

An animation in three parts. First, git diff on a PDF prints only "Binary files
a/CommunicationModel_en.pdf and b/CommunicationModel_en.pdf differ". Then OmniDiff, as git's
external diff, reports that the metadata and page 1 changed and where. Then OmniDiff's viewer lists
the changed members and shows page 1 before and after side by side, the renamed box outlined on
both, and then the difference alone.

An animation of a Font Awesome web font. git diff prints only "Binary files differ"; OmniDiff
reports 21 changed members and lists each changed glyph; its viewer shows the font's name table
with the version and style changed, one glyph before and after, and then all twenty changed icons
in a grid, each change outlined.

Installation

From source

文本
cargo install --locked omnidiff

This command builds OmniDiff from source, with the dependency versions it was tested with. You need a C compiler on PATH and a Rust toolchain, rustc 1.92 or later. The build compiles every tree-sitter grammar from C. The first cargo install takes a few minutes, because of this and the lto = "fat" release profile.

Prebuilt binaries

Prebuilt binaries for Linux, macOS (Intel and Apple Silicon), and Windows are attached to every GitHub release.

Homebrew

macOS and Linux:

文本
brew install ivankovic/omnidiff/omnidiff

Debian and Ubuntu

.deb packages for amd64 and arm64 are available in a signed apt repository:

SH
sudo install -d -m 0755 /etc/apt/keyrings
curl -fsSL https://ivankovic.github.io/omnidiff/apt/omnidiff-archive-keyring.gpg \
  | sudo tee /etc/apt/keyrings/omnidiff-archive-keyring.gpg > /dev/null
echo "deb [signed-by=/etc/apt/keyrings/omnidiff-archive-keyring.gpg] \
https://ivankovic.github.io/omnidiff/apt stable main" \
  | sudo tee /etc/apt/sources.list.d/omnidiff.list > /dev/null
sudo apt update && sudo apt install omnidiff

Nix and NixOS

On NixOS, or anywhere with Nix installed:

文本
nix run github:ivankovic/omnidiff

If flakes are not enabled in your Nix configuration, add --extra-experimental-features 'nix-command flakes' after nix.

Arch and Gentoo

Recipes for Arch and Gentoo live in packaging/: the PKGBUILD builds locally with makepkg -si, and the Gentoo ebuild is ready for an overlay. The two distros are overwhelmed and their repositories open and close to new packages sporadically.

Editor integration

VS Code does not yet let an extension replace its built-in diff view. The API is implemented upstream but unreleased; the extension will adopt it when it ships.

  • VS Code - omnidiff-vscode. Search for OmniDiff in the Extensions view, or code --install-extension ivankovic.omnidiff. Also on Open VSX for VSCodium, Cursor and Windsurf.
  • Neovim - omnidiff.nvim.

Using OmniDiff

The interactive TUI

文本
omnidiff                  # open an empty viewer; press o to pick each file
omnidiff BEFORE AFTER     # open directly into the diff of two files

Press ? in the viewer for the full list of keybindings.

The TUI uses 24-bit color when the terminal advertises it with COLORTERM=truecolor, and the nearest 256 colors otherwise (macOS Terminal.app, or most terminals over ssh, which does not forward COLORTERM). If your terminal supports 24-bit color but does not advertise it, run export COLORTERM=truecolor.

In a browser

For reviewing changes in a browser, see codereview.

Note: codereview is at v0.0.0; use it at your own risk.

(注:更多技术实现细节与完整 API 文档请查阅原项目 README)


作者发帖说明(HN):

I have been researching what the ultimate diff tool would look like, based on actual diffs in open source repositories.

OmniDiff can diff: code (25 languages), config, images, PDFs, archives, cursors, fonts...

It's fast. It can diff C++ files of tens of thousands of lines in under 100ms, on a 2023 ThinkPad T14s.

It's open source. AGPLv3.

It's based on real diffs. I looked at the 7400 repositories that are listed in Gentoo packages, sampled 2000 diffs and solved them manually to get a good understanding of what is needed, before putting together the diff pipelines for each content type. Incidentally, this also forms the basis of the CI pipeline, so the robustness of the codebase is quite high.

I'm still developing it. It's v0.3.0 at this time. But I have been using it daily as my git difftool for months now, and it works well.

AI Disclosure: Yes, I do use AI. No, I do not vibecode.