Not every comparison happens in a Git repository. Config files get edited manually. API responses get pasted into a Slack thread. SQL queries get tweaked across versions in a spreadsheet. When you need to see exactly what changed between two pieces of text, you need a diff tool — just not necessarily Git.
Here’s how to pick the right one.
When You Need a Diff Outside of Git
Git’s diff is baked into your workflow when files are version-controlled. But plenty of situations fall outside that:
- Config files — comparing
nginx.confbefore and after a change, especially if the file isn’t in a repo - API response snapshots — spotting what changed between two JSON payloads captured a week apart
- SQL queries — comparing a query that runs in dev vs the one running in prod
- Документация — reviewing a manually edited doc before handing it off
In these cases, you want a clean comparison without needing a commit or a staged file.
The Unix diff Command: Flags That Matter
If you’re on Linux or macOS, diff is already installed. The basic usage is:
diff file1.txt file2.txt
But the default output is terse. These flags make it readable:
# Unified format (same as Git's diff output — most familiar)
diff -u file1.txt file2.txt
# Side-by-side comparison
diff -y file1.txt file2.txt
# Ignore whitespace differences (useful for formatting changes)
diff -w file1.txt file2.txt
# Combine: unified format, ignore whitespace
diff -uw file1.txt file2.txt
Sample unified output:
--- file1.txt 2026-03-01 10:00:00
+++ file2.txt 2026-03-05 14:30:00
@@ -1,4 +1,4 @@
server {
- listen 80;
+ listen 443;
server_name example.com;
}
Строки, начинающиеся с - were removed, + were added. Lines with no prefix are unchanged context.
Three-Way Diff: When You Have Three Versions
A standard diff compares two files. A three-way diff handles a third — the common ancestor. This is how merge conflict resolution works under the hood, even outside of Git.
The diff3 command handles it:
diff3 mine.txt base.txt theirs.txt
This shows what changed in mine.txt vs base.txt, and what changed in theirs.txt vs base.txt — flagging any conflicts. Useful when two people have independently edited the same starting document and you need to reconcile them without a Git merge.
Programmatic Diffing: Python and Node.js
When you need to diff inside a script — or build diff output into an application — use a library instead of shelling out to diff.
Python — difflib:
import difflib
text1 = open("file1.txt").readlines()
text2 = open("file2.txt").readlines()
diff = difflib.unified_diff(text1, text2, fromfile="file1.txt", tofile="file2.txt")
print("".join(diff))
difflib also includes HtmlDiff for generating side-by-side HTML output, and SequenceMatcher for getting a similarity ratio between two strings — handy for fuzzy matching.
Node.js — diff package:
npm install diff
const Diff = require('diff');
const one = 'SELECT id, name FROM users WHERE active = 1;';
const two = 'SELECT id, name, email FROM users WHERE active = 1 LIMIT 100;';
const changes = Diff.diffWords(one, two);
changes.forEach(part => {
if (part.added) process.stdout.write('\x1b[32m' + part.value + '\x1b[0m');
else if (part.removed) process.stdout.write('\x1b[31m' + part.value + '\x1b[0m');
else process.stdout.write(part.value);
});
The diff library supports character, word, line, sentence, JSON, and CSS diffing out of the box.
When an Online Tool Is the Right Call
The CLI is fast if you already have two files on disk. But when you’re comparing text copied from two sources — a Slack thread, two API responses, clipboard content — opening a terminal and writing temp files is overkill.
A browser-based text compare tool is the fastest path for:
- One-off comparisons with no files on disk
- Sharing a diff with someone who doesn’t use the terminal
- Checking a before/after paste without any setup
IO Tools Text Compare handles this directly in the browser with syntax highlighting and no file upload required. Paste two texts, see the diff immediately.
Diffing Structured Data: JSON and YAML Are Different
Plain text diff works line by line. JSON and YAML have structure — and formatting differences (indentation, key order) produce meaningless noise in a standard diff.
For JSON, normalize first:
jq --sort-keys . file1.json > file1_normalized.json
jq --sort-keys . file2.json > file2_normalized.json
diff -u file1_normalized.json file2_normalized.json
This strips formatting variation and shows only real content changes. For YAML, tools like dyff understand the structure and report differences semantically rather than line-by-line.
| Случаи использования | Best tool | Примечания |
|---|---|---|
| Plain text files | diff -u | Standard, works everywhere |
| Side-by-side in terminal | diff -y | Wide output, good for short files |
| Merge conflicts (no Git) | diff3 | Three-way comparison |
| Scripted or automated diff | Питон difflib or Node diff | Build into pipelines or apps |
| Quick paste comparison | IO Tools Text Compare | Browser-based, no setup |
| JSON with formatting noise | jq normalize + diff | Sort keys, then diff |
| ЯМЛ | dyff, yamldiff | Structure-aware, better signal |
Which Tool When
- Two files on disk →
diff -u - Need to ignore whitespace →
diff -uw - Three versions to reconcile →
diff3 - Building a pipeline or script →
difflibилиdiffnpm package - Comparing two pastes in a browser → IO Tools Text Compare
- Diffing JSON → normalize with
jq, thendiff - Diffing YAML → use
dyff
The fastest method is whichever fits your starting point. If the text is already in your clipboard, a browser diff tool beats any terminal workflow. If it’s in files, diff is already on your machine.
Вам также может понравиться
Установите наши расширения
Добавьте инструменты ввода-вывода в свой любимый браузер для мгновенного доступа и более быстрого поиска
恵 Табло результатов прибыло!
Табло результатов — это интересный способ следить за вашими играми, все данные хранятся в вашем браузере. Скоро появятся новые функции!
Подписаться на новости
все Новые поступления
всеОбновлять: Наш последний инструмент было добавлено 4 мая 2026 года
