⚖️ 比较 · 高亮 · 补丁

文本比较器

比较两段文本并在并排统一内联视图中高亮差异。采用Myers差分算法 — 与Git和GitHub使用的算法相同。

Original (A)

修改版 (B)

一款完全在浏览器中运行的专业差异比较工具

This page implements the same Myers diff algorithm that Git, GitHub, GitLab, VS Code and most "diff" tools use. It finds the shortest edit script — the smallest sequence of insertions and deletions to turn one text into the other. The result is a clean, intuitive comparison without spurious "everything changed" noise.

三种视图模式

三种比较粒度

忽略选项

为什么选择Myers而不是更简单的算法?

Naive longest-common-subsequence diff is O(N·M) in time and memory — fine for a few hundred lines but slow on real files. Myers' algorithm is O(N·D), where D is the size of the actual diff. For typical inputs (most lines unchanged), D is small and the algorithm runs in near-linear time. Our implementation handles 500-line diffs in milliseconds.

隐私

Both texts are diffed entirely in your browser tab. We don't upload, we don't log, we don't analyze. No external library is loaded — the algorithm is ~120 lines of vanilla JavaScript embedded in the page.

导出

The Copy as unified patch button copies a diff -u-style patch to your clipboard, ready to paste into a GitHub comment, a Slack message, or to save as a .patch file.

常见使用场景

常见问题

差异比较器如何工作?
该工具使用 diff-match-patch 算法(Google 的开源库)比较两段文本,并高亮显示添加、删除和修改的行。所有处理都在浏览器中完成——您的文本不会被上传到任何地方。
差异比较器会上传我的文本吗?
不会。比较完全在您的浏览器中使用 JavaScript 进行。您的文本永远不会离开设备,不会被存储、传输或记录。非常适合比较敏感代码或文档。
支持哪些比较模式?
支持并排(side-by-side)和统一(unified)两种视图模式。您可以逐行比较或逐字符比较,还可以忽略空白字符差异。
可以比较什么类型的文本?
任何纯文本内容——代码、配置文件、JSON、文章、翻译等。工具不限制文件类型或内容长度,适合各种文本比较需求。
差异比较器免费吗?有使用限制吗?
完全免费,没有使用限制、无需注册。处理在浏览器本地进行,因此唯一的限制是设备内存。可以轻松处理数千行的文本比较。

相关工具