Diff Checker
Compare two texts line by line and see exactly what changed.
| - | function greet(name) { |
| - | console.log("Hello, " + name); |
| - | return name; |
| + | function greet(name, greeting = "Hello") { |
| + | console.log(greeting + ", " + name + "!"); |
| } | |
| const user = "Alice"; | |
| + | const admin = "Bob"; |
| greet(user); | |
| + | greet(admin, "Hi"); |
テキスト差分 — 何が変わったのか?
一般的な用途
LCS差分の仕組み
ドキュメントやコードファイルの2つのバージョン間で何が変わったかを正確に把握することは、ソフトウェア開発とコンテンツ作業において最も一般的なタスクの一つです。diffツールは、元のバージョンから修正版に移行するために必要な最小限の変更を表示します。
最長共通部分列(LCS)アルゴリズムは、両テキストに同じ順序(ただし必ずしも連続していない)で存在する行の最大セットを見つけます。この共通セットにある行は「変更なし」です。それ以外はすべて追加(修正版のみに存在)または削除(元のバージョンのみに存在)です。これはgit、diff、およびほとんどのバージョン管理システムで使われている基本的なアルゴリズムと同じです。
末尾のスペースや空行は誤解を招くdiffを引き起こす可能性があります。一見同一に見える行が、見えない末尾スペースによって変更として表示されることがあります。コードを比較する場合は、貼り付け前にエディタで末尾の空白を削除してください。300行を超える大きなファイルでは、LCSアルゴリズムがより単純な全体置換ビューに劣化します。詳細なdiffを得るには、ファイルをセクションに分けてそれぞれを個別に比較してください。
- コードレビュー — コミット前にファイルの変更点を確認
- 設定ファイル — 本番環境とステージング環境の設定の違いを特定
- 法的文書・契約 — 合意書の2つのバージョンを比較
- コンテンツ編集 — 編集者がドラフトに加えた変更を追跡
- デバッグ — 設定やコードスニペットの動作する版と壊れた版を比較
よくある質問
- How does the diff checker work?
- The tool uses the Longest Common Subsequence (LCS) algorithm to find lines that appear in both texts. Lines only in the original are shown in red (removed), lines only in the modified are shown in green (added), and common lines are shown without highlighting.
- What can I use this for?
- Comparing versions of code, configuration files, documents, or any text. It's useful for reviewing changes before committing to version control, comparing contract revisions, checking what changed between two versions of a file, or spotting differences in two similar text blocks.
- Is there a character or line limit?
- The LCS algorithm is limited to 300 lines per side for performance. For texts longer than this, a simplified fallback is used showing all original lines as removed and all modified lines as added. For large file diffs, use a dedicated version control tool like git diff.
- Does the diff work on word level or line level?
- This tool performs line-by-line comparison. Each entire line is compared as a unit. This is the standard approach for code and document diffs — the same method used by git diff by default.
- Is my text sent to a server?
- No. All comparison happens entirely in your browser. No data is transmitted or stored.
関連ツール
- JSON Formatter, Validator & Repair Tool
Format, minify, validate, and repair JSON instantly in your browser. Sort keys alphabetically, auto-format on paste, download as file, escape/unescape strings — free, no sign-up, 100% client-side.
- QRコード生成
URL、テキスト、Wi-FiなどのQRコードを生成。PNGでダウンロード可能。
- パスワード生成
カスタム長と文字セットで強力なランダムパスワードを生成。
- Base64 エンコーダー / デコーダー
テキストをBase64にエンコード、または逆にデコード。
- URLエンコーダー / デコーダー
パーセントエンコーディングでURLとクエリ文字列をエンコードまたはデコード。