文本比较器
比较两段文本并在并排、统一或内联视图中高亮差异。采用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.
三种视图模式
- 并排 — two aligned columns, like a code review tool. Best for inspecting code diffs at a glance.
- 统一 — git-diff format with
+/−prefixes. Best for sharing patches in chat or documentation. - 内联 — changes shown within the flow, with deletions struck through and insertions underlined. Best for prose, blog posts, contracts.
三种比较粒度
- 行 (default) — the standard for source code and most documents.
- 单词 — best for prose where line breaks are arbitrary. Highlights the actual changed words.
- 字符 — every single character compared. Useful for short strings, IDs, and detecting subtle differences (a Greek letter swapped for a Latin one, a comma changed to a period).
忽略选项
- Whitespace — treat lines/words/characters as equal even if their spacing differs. Essential when comparing code where someone re-formatted.
- Case — case-insensitive comparison. Useful when one source is normalized.
- Empty lines — drop blank lines before comparing. Useful when only paragraph spacing changed.
为什么选择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.
常见使用场景
- 比较配置文件或YAML清单的两个版本。
- 查看两个AI生成草稿之间的确切变化。
- 逐字核实法律合同修订版本。
- 在长字符串(API密钥、哈希、URL)中发现单字符错误。
- 无需先提交到git即可生成可分享的代码变更补丁。
常见问题
- 差异比较器如何工作?
- 该工具使用 diff-match-patch 算法(Google 的开源库)比较两段文本,并高亮显示添加、删除和修改的行。所有处理都在浏览器中完成——您的文本不会被上传到任何地方。
- 差异比较器会上传我的文本吗?
- 不会。比较完全在您的浏览器中使用 JavaScript 进行。您的文本永远不会离开设备,不会被存储、传输或记录。非常适合比较敏感代码或文档。
- 支持哪些比较模式?
- 支持并排(side-by-side)和统一(unified)两种视图模式。您可以逐行比较或逐字符比较,还可以忽略空白字符差异。
- 可以比较什么类型的文本?
- 任何纯文本内容——代码、配置文件、JSON、文章、翻译等。工具不限制文件类型或内容长度,适合各种文本比较需求。
- 差异比较器免费吗?有使用限制吗?
- 完全免费,没有使用限制、无需注册。处理在浏览器本地进行,因此唯一的限制是设备内存。可以轻松处理数千行的文本比较。