DevToolBox

Diff Checker

2つのテキストを並べて比較し、差分をハイライト表示します。

How to Use the Diff Checker

This free online diff checker compares two blocks of text and highlights the differences line by line. Paste your original text on the left and the modified version on the right, then click "Compare" to see an instant unified diff view. Lines that were removed are shown in red with a minus prefix, added lines appear in green with a plus prefix, and unchanged lines are shown without highlighting. All comparison is done entirely in your browser so your text is never uploaded to any server.

What is a Diff?

A diff (short for difference) is a comparison between two texts that shows what has changed between them. The concept originated in Unix with the diff command and is fundamental to version control systems like Git. Diffs are essential for code reviews, document editing, configuration management, and any workflow where tracking changes matters. This tool uses the Longest Common Subsequence (LCS) algorithm to produce an accurate, minimal diff output.

Common Use Cases

Developers use diff tools to compare code changes before committing, review pull requests, debug configuration file changes, and verify that automated edits were applied correctly. Writers and editors use diffs to track revisions in documents. System administrators compare configuration files between environments to find discrepancies. This tool handles any plain text including source code, configuration files, log files, and prose.

Tips for Better Comparisons

For the most readable results, make sure both texts use the same line ending style (LF vs CRLF). If comparing code, ensure consistent formatting first to avoid noise from whitespace differences. For large files, consider comparing specific sections rather than the entire file. The diff output can be scrolled vertically to review all changes, and the change count at the top gives you a quick summary of how many lines differ.

Diff Checkerの使い方

2つのテキストを行単位で比較し、追加・削除された行をハイライト表示するツールです。左の入力欄に元のテキスト、右の入力欄に変更後のテキストを貼り付けて「比較」ボタンを押すと、LCS(最長共通部分列)アルゴリズムで算出した最小限の差分が表示されます。削除行は赤に「-」、追加行は緑に「+」のプレフィックスが付き、差分結果の上部には変更行数のサマリーが出ます。コードレビューや設定ファイルの比較、ドキュメント修正の確認などに便利です。全ての処理はブラウザ内で完結します。

JSON Diff(構造比較)との使い分け

本ツールは「行の並び」を比較する行diffです。JSONのようにキーの順序やインデントが変わり得るデータでは、意味的に同じ内容でも大量の行差分が出てしまいます。JSONを比較するなら、キー順序や整形差を無視して構造的な違いだけを検出するJSON Diffを使ってください。逆に、ソースコード・ログ・散文のように「行そのもの」に意味があるテキストは本ツールが適しています。

実務での活用例

1. 設定ファイルの環境間比較

ステージングと本番で挙動が違うとき、nginx.conf や .env、Kubernetes マニフェストを左右に貼って比較すると、差し替え漏れや値の食い違いが数秒で見つかります。接続文字列や認証情報を含むファイルでも、ブラウザ内処理のため外部に渡る心配がありません。

2. AI・自動整形ツールの出力検証

生成AIに「この関数をリファクタして」と頼んだ結果や、Prettier 適用後のコードを元コードと比較すれば、意図しない変更が紛れ込んでいないかを目視で確認できます。「修正は1箇所のはず」が実は3箇所変わっていた、という事故を未然に防げます。

3. ドキュメント・規約文面の改訂チェック

「軽微な修正です」と送られてきた契約書や利用規約の新旧テキストを比較すると、変更箇所を漏れなく洗い出せます。Word の変更履歴が消されていても、テキストさえ抽出できれば差分を再現できます。

よくある落とし穴 / Common Pitfalls

「同じはずなのに差分が出る」と感じたときは、ほとんどの場合、目に見えない文字の違いが原因です。

When two texts "look identical" but the tool reports differences, invisible characters are almost always the culprit.

症状 / Symptom原因 / Cause対処 / Fix
全行が差分として表示される
Every line is marked as changed
改行コードの違い(CRLF と LF)
Line ending mismatch (CRLF vs LF)
エディタで改行コードを統一(VS Code は右下の CRLF/LF 表示から変更可)
Normalize line endings in your editor (VS Code: status-bar CRLF/LF toggle)
見た目が同じ行に差分が出る
Visually identical lines differ
行末の空白(trailing whitespace)
Trailing whitespace at end of line
保存時に行末空白を削除する設定を有効化
Enable "trim trailing whitespace on save"
スペース位置は同じなのに差分
Spacing looks the same but differs
全角スペース(U+3000)と半角スペースの混在
Full-width space (U+3000) mixed with regular space
全角スペースを検索して置換する
Search for full-width spaces and replace them
1文字も違わないように見えるのに差分
No visible difference at all, yet flagged
不可視文字(ZWSP・NBSP・BOM)の混入
Invisible characters (ZWSP, NBSP, BOM)
Unicode Inspector に貼ってコードポイントを特定し除去
Paste into Unicode Inspector to locate and remove them
JSONを比較すると大量の差分が出る
Comparing JSON yields a wall of diffs
キー順序・インデントの違いは行比較では全て差分扱い
Key order and indentation changes all count as line changes
構造比較ができる JSON Diff を使う
Use JSON Diff for structural comparison
インデント整理しただけで全行差分
Re-indenting marks every line changed
タブとスペースの混在、フォーマッタの設定差
Tabs vs spaces, or different formatter settings
比較前に両方を同じフォーマッタで整形する
Run both texts through the same formatter first
行を移動しただけなのに「削除+追加」になる
A moved line shows as delete + add
LCSベースの行diffは行の移動を検出しない
LCS-based line diffs do not detect moves
仕様として理解する。移動が多い場合は git diff --color-moved 等を利用
Expected behavior; use git diff --color-moved when moves matter

言語別コード例 / Code Examples by Language

行単位のdiffをプログラムから取得するための最小サンプルです。

Minimal snippets to compute a line-based diff programmatically.

JavaScript (jsdiff)

import { diffLines } from "diff"; // npm install diff

for (const part of diffLines(oldText, newText)) {
  const mark = part.added ? "+" : part.removed ? "-" : " ";
  console.log(mark, part.value.trimEnd());
}

Python (difflib)

import difflib

old_lines = old_text.splitlines(keepends=True)
new_lines = new_text.splitlines(keepends=True)
for line in difflib.unified_diff(old_lines, new_lines,
                                 fromfile="before", tofile="after"):
    print(line, end="")

Go (go-diff)

import "github.com/sergi/go-diff/diffmatchpatch"

dmp := diffmatchpatch.New()
diffs := dmp.DiffMain(oldText, newText, false)
fmt.Println(dmp.DiffPrettyText(diffs))

Shell

# unified diff 形式で比較 / Compare in unified diff format
diff -u before.txt after.txt

# Gitリポジトリ外のファイルでも git diff を使う / git diff outside a repo
git diff --no-index before.txt after.txt

# CRLF・空白数の違いを無視 / Ignore CRLF and whitespace-amount changes
diff -u --strip-trailing-cr -b before.txt after.txt

Before / After 実例 / Before & After

例1: 設定ファイルの1行変更 / A one-line config change

server {
  listen 80;
  server_name example.com;
}

↓ 変更後と比較した出力 / Diff output against the modified version

  server {
- listen 80;
+ listen 443 ssl;
  server_name example.com;
  }

例2: 改行コード差で全行差分 / CRLF vs LF makes every line differ

hello
world

↓ 左がCRLF・右がLFの場合、見た目が同一でも全行が差分になります / If one side uses CRLF and the other LF, every line is flagged

- hello
- world
+ hello
+ world

例3: JSONのキー順序違い / JSON key order

{"name": "Koba", "age": 30}
{"age": 30, "name": "Koba"}

↓ 行比較では「削除+追加」の差分になります / A line diff reports delete + add

- {"name": "Koba", "age": 30}
+ {"age": 30, "name": "Koba"}

意味的には同一のJSONです。この場合は JSON Diff なら「差分なし」と判定されます。

Semantically these are the same JSON. JSON Diff would report "no differences" here.

Why browser-only? / なぜブラウザ完結か

The texts people diff are often their most sensitive ones: production config files with database credentials, proprietary source code before a commit, draft contracts, or HR documents under revision. A server-hosted diff service requires uploading both versions in full — twice the exposure of a typical paste tool. DevToolBox computes the LCS-based diff entirely in your browser with plain JavaScript. No network request is made when you click "Compare," nothing is logged, and nothing is stored. You can verify this yourself: open DevTools, switch to the Network tab, run a comparison, and watch the tab stay empty. When you close the page, both texts are gone.

差分比較にかけるテキストは、DB接続情報を含む本番設定ファイル、コミット前のソースコード、改訂中の契約書など、機密性の高いものが多くあります。サーバ型のdiffサービスでは新旧2つの全文をアップロードする必要がありますが、本ツールはLCSによる差分計算をすべてブラウザ内のJavaScriptで実行します。「比較」を押しても通信は発生せず、保存もされません。DevTools の Network タブが空のままであることで確認できます。 1文字も変えていないのに全行が差分になる場合は改行コードCRLFとLFの違いと統一方法を確認してください。

開発をもっと効率的に

PR