# Code review and propagation across git branches

> Online side-by-side diff free for text and JSON with Myers algorithm: 4 modes (lines, words, chars, JSON struct), export as unified patch diff -u.

Free in-browser tool (no upload): https://www.mauriziofonte.it/tools/text-diff-online

**Side-by-side** comparison of two texts or two JSON payloads using the **Myers** algorithm. Four diff modes: lines, words, characters or parsed JSON structure. Output also available as a **unified patch** in `diff -u` format, applicable with `git apply` or the classic `patch -p0`: useful for code review, propagating changes across branches, or generating a reusable technical changelog for pipelines.

## How to use the diff tool

1. **Paste the two texts** - Left (Original) the starting text, right (Modified) the modified version. The fields accept any text: code, JSON, logs, command output, anything.
2. **Pick the mode** - Lines for source code or config files. Words for prose or documentation (better at fragmented edits). Characters for single-line tweaks. JSON for structural comparison (handles key reorder, nested objects).
3. **Read the diff** - Side-by-side: two columns, left with removed (red strike-through), right with added (green). Inline: a single column with + and - markers. Stats at the top: characters added, removed, unchanged.
4. **Export as patch** - The unified patch format (`diff -u`) is compatible with `git apply`, `patch -p0`, code review tools. Copy/download to apply the diff to a repo or for review.

## What sets it apart, in practice

**JSON-aware.** A string-level diff between two JSON payloads formatted differently produces poor results: 80% of the lines come up as changed for pure whitespace or key-ordering reasons, while the actual logical change is just one. The JSON mode of this tool parses the two inputs before comparing, ignores whitespace and re-serializes the diff with consistent indentation. The result highlights only the actual logical differences between the two payloads.

**Operational privacy.** Code, application logs, configs and real JSON payloads are often confidential: they contain internal identifiers, passwords in comments, data model structure, references to private backends. The diff computation happens directly in the browser on the two texts you paste, without transferring them to a third-party service that might log or archive them.

**Standard unified patch.** The output in `diff -u` format follows the POSIX standard with `---/+++` headers, `@@ -L,N +L,N @@` hunks and context lines. It can be applied directly with `git apply changes.patch` or with `patch -p0 < changes.patch`, and pasted into any code review tool. No proprietary format, no trial limit on export.

## Glossary

- **Myers algorithm**: Algorithm for computing the longest common subsequence (LCS) and therefore the minimum edit script between two sequences. Eugene Myers, 1986. Complexity O(N+M+D^2) with D = number of edits. De-facto standard for text diff.
- **Unified patch**: Textual format to express differences between two files. Headers with names, hunks prefixed by `@@ -L,N +L,N @@`, modified lines prefixed by +/-, context lines unprefixed. POSIX standard, applicable with `patch` or `git apply`.
- **Side-by-side diff**: Two-column visualization: left the original, right the modified. Common in code review tools (GitHub, GitLab, Phabricator). Variants: 'inline' or 'split' (GitHub terminology).
- **JSON structural diff**: JSON comparison that parses both inputs before diffing, ignoring whitespace and key order. Implementation-dependent: some libraries treat `{a:1, b:2}` and `{b:2, a:1}` as identical, others not. jsdiff treats them as different (order matters).
- **Hunk**: Section of a unified patch describing a contiguous block of changes. Starts with `@@` and contains context, +, - lines. File with many distant changes = many separate hunks.

## Frequently asked questions

### Can I diff binary files (images, PDFs, executables)?

No. This tool is text-only. For binary files: `cmp -l a.bin b.bin` shows differing bytes at the shell level, or dedicated tools like `vbindiff` or `radiff2`. For images: ImageMagick `compare` or dedicated graphical tools.

### Does JSON diff treat different key order as 'identical'?

No. The JSON mode of jsdiff parses both inputs but then serializes with the same indent and order, showing differences including key reordering. To ignore key order: first sort the keys (e.g. with the realm's JSON formatter), then compare. Clean result: only value differences, no ordering noise.

### Does it work offline after the first load?

Yes. The jsdiff library is loaded via vendor, no server fetch. Once cached, the tool works without network. Bookmark for air-gapped use.

### Is the generated patch compatible with git apply?

Yes. createPatch() from jsdiff produces standard unified output (`diff -u`), with header, hunks, context lines. Directly applicable via `git apply changes.patch` in a repo where the 'left' version is the current state. For other tools: `patch -p0 < changes.patch` for top-of-file patches.

### Is there a size limit for inputs?

Nothing hardcoded. Browser tab memory is the limit. 100KB-1MB files are comfortable, beyond 5MB the UI may slow down (Myers is O(N+M+D^2), the D^2 grows with the delta). For huge files: `diff -u file1 file2` at the command line is more efficient.

### Can I do 3-way diff (3-way merge)?

Not in V1. jsdiff does not implement 3-way merge. For that: `git merge-file`, `kdiff3`, `meld` are the standard tools. I will add it as a dedicated tool in the future if the roadmap calls for it.

### Is Words mode good for technical documents?

Yes. It is better than Lines for documentation and prose (markdown, AsciiDoc) because changing a single word in the middle of a paragraph does not show up as 'whole line changed'. For source code, Lines remains better (edits are per line).

### Differences between Myers and patience diff (git default in some configs)?

Patience diff is a variant that starts from 'unique lines' (lines that appear only once in each file) and uses them as anchors. Typically produces more readable diffs in case of refactors (block reordering). jsdiff implements classic Myers. For code with big refactors, git diff with --patience or --histogram may be preferable to a pure Myers diff.

---
Tool by Maurizio Fonte, senior backend engineer. All tools: https://www.mauriziofonte.it/tools/
