Unified Diff to Patch File Generator

Create a .patch file from two pasted text versions, with line context.

Ad placeholder (leaderboard)

A unified diff is the patch format git and the patch tool understand: it records exactly which lines were removed and added, wrapped in hunks with location headers and a few lines of surrounding context. This generator diffs two pasted texts and emits a clean .patch file you can share or apply offline.

How it works

  1. Both inputs are split into lines.
  2. A longest-common-subsequence (LCS) diff finds the minimal edit script — the smallest set of line deletions (-) and insertions (+) that turns the original into the modified text; matching lines become context ( ).
  3. Consecutive changes are grouped into hunks, each padded with up to N lines of context (default 3) and separated when the gap between changes exceeds 2×N.
  4. Each hunk gets an @@ -start,len +start,len @@ header, and the file gets --- a/<name> / +++ b/<name> headers.

Example

For an original ending color: red; changed to color: blue;, a 1-line-context hunk looks like:

@@ -1,3 +1,3 @@
 .btn {
-  color: red;
+  color: blue;
 }

Notes

Line numbers in the hunk header are 1-based, and the lengths count the context plus changed lines on each side — exactly what git emits. A trailing-newline difference is handled so the patch applies cleanly. Everything is computed locally; your text never leaves the browser.

Ad placeholder (rectangle)