Patch File Viewer with Word-Level Highlights
Operator: Abdulla Al Fahad. How tools are built and checked
A colleague mails you 0001-retry-uploads.patch and the only tools that read it are a checkout and git apply. Open the file here instead: each changed file gets its own panel, deleted and added lines are numbered against both versions, and when one line was rewritten only the words that differ are marked, so a retry loop around an existing fetch call does not look like a total rewrite.
Key features
- Unified diffs and git format-patch files, including series of several patches with their commit messages
- Inline or side-by-side layout, with line numbers for the old and the new file
- Word-level highlights inside lines that were changed rather than added or removed
- Unchanged context trimmed to 0 to 3 lines around each change, with a button to show what was hidden
How the patch text is read
Files begin at a diff --git line, or at a --- and +++ pair for plain diff -u output. Renames and copies are read from their similarity index and rename or copy lines, new and deleted files from their mode lines, and binary changes (Binary files differ and GIT binary patch) are listed without a body. Quoted git paths with octal escapes, such as accented file names, are decoded.
Hunks are read by their @@ -a,b +c,d @@ counts, not by guessing from the first character, so a removed line whose text starts with -- or a context line that looks like a header is not mistaken for one. If a patch ends before a hunk has all its lines, that file shows a truncation warning. Combined diffs (diff --cc) are skipped with a note.
How it works
For each run of deleted lines followed by added lines, the first deleted line is paired with the first added line, and so on. Each pair is split into words, spaces and punctuation, and a longest-common-subsequence comparison marks what changed. Pairs are skipped when a line is longer than 600 characters or has more than 250 tokens, and a pair that shares nothing but whitespace is left unmarked.
When this helps
- A maintainer receives a 40-file patch series from a contributor, filters the list to test, collapses the 12 files she has read, and exports one HTML file to attach to the review ticket.
- An auditor checks a vendor's patch for a renamed configuration file and sees it listed as renamed with a 94% similarity and a three-line change, rather than as one deleted and one added file.
Opening a file
- Drop a .patch or .diff file or paste the text, then press View patch.
- Choose inline or side-by-side and how many unchanged lines to keep.
- Use the file filter, or click a file name in the summary list to jump to it, and collapse files you have finished.
Example
The built-in patch: one file, src/upload.js
@@ -10,9 +10,12 @@
- const res = await fetch(opts.url, { method: "PUT", body: file });
- if (!res.ok) throw new Error("upload failed");
- return res.json();
+ for (let attempt = 1; attempt <= 3; attempt += 1) {
+ const res = await fetch(opts.url, { method: "PUT", body: file });
+ if (res.ok) return res.json();
+ await sleep(attempt * 500);
+ }
+ throw new Error("upload failed after 3 attempts");Summary and context trimming
1 file, +6 -3, subject "Retry failed uploads three times"
With 1 unchanged line kept around the change, 2 unchanged lines at the start and 2 at the end are hidden behind "Show 2 unchanged lines".Limits
Long lines are cut at 2,000 characters in the view and in the export, with a note of how many characters were dropped; a minified file in a patch is not shown in full.
The view shows at most the first 1,500 lines of a file at a time, counted from its first hunk, and the first 200 files; use the filter and the Show more button, or the export, which holds everything.
Line endings are normalised when the text is read, so a patch that only converts a file from LF to CRLF shows every changed line twice, once removed and once added, with identical text and no highlighted words. If two adjacent lines look the same, that is the usual reason; the only sign is the count at the top, which still reports each line as both removed and added.
A renamed file that was also edited appears as one panel named old -> new, with the similarity badge (for example renamed 94%) and only the edited lines counted as +1 -1. A rename at 100% similarity has no hunks, so its panel shows the badge and nothing else; a review of such a patch has to read the path, not a diff.
- Set the context to None for a first pass over a large patch: only changed lines remain, and the per-file counts in the list show where the volume is.
Common errors and how to fix them
- "This does not look like a unified diff or git patch: there is no diff --git line and no --- / +++ pair."
- The text has no file headers. A bare list of @@ hunks cannot be placed in a file, so copy the whole diff including its header lines, or the output of git diff or git format-patch.
What the HTML export contains
The export is one file with its styles inline. It has no scripts, a Content-Security-Policy that blocks every request, and every file name, commit message and source line passes through HTML escaping, so a patch containing <script> or an image tag with an onerror handler is displayed as text. Files are shown as open <details> blocks, with changed words marked and context trimmed the way it is on screen.
Frequently asked questions
Why does a removed line sit above an identical added line?
The two lines differ in something the view does not draw, most often a line ending (LF to CRLF). The diff counts both lines because git did, and the line text on screen has no carriage return to show the difference.
Does it apply the patch or check that it applies?
No. It reads the diff text only and has no access to the files it describes, so it cannot tell whether a patch applies cleanly to your tree. For two plain texts that are not in diff form, Text Compare here is the right tool.