Unified Diff Generator
Compare two texts and generate a real unified diff patch with @@ hunk headers and configurable context, ready to save as .patch and apply with git apply.
Unified diff (.patch)
--- a/original.txt+++ b/modified.txt@@ -1,5 +1,6 @@-function greet(name) {- console.log("Hello, " + name);+function greet(name, greeting) {+ const text = greeting || "Hello";+ console.log(text + ", " + name);}-greet("world");+greet("world", "Hi");
What is the Unified Diff Generator?
Paste an original and a modified version of any text and this tool produces a genuine unified diff — the same format git diff and diff -u emit, with --- and +++ file headers, @@ hunk headers and +/- line prefixes.
- Real unified diff output with correct @@ -l,s +l,s @@ hunk headers
- Configurable context radius from 0 to 20 lines, with GNU-compatible hunk merging
- Options to ignore whitespace changes and letter case
- Added, removed and unchanged line counts at a glance
- Colour-coded preview and a downloadable .patch file
- Runs entirely in your browser — nothing is uploaded
How to use the Unified Diff Generator
- 1
Paste the original text on the left and the modified text on the right.
- 2
Set the file names used in the --- a/ and +++ b/ headers.
- 3
Choose how many context lines to include around each change; git uses 3.
- 4
Optionally ignore whitespace changes or letter case when comparing.
- 5
Review the colour-coded patch, then copy it or download it as changes.patch.
About the Unified Diff Generator
Paste an original and a modified version of any text and this tool produces a genuine unified diff — the same format git diff and diff -u emit, with --- and +++ file headers, @@ hunk headers and +/- line prefixes. The output is a real patch you can save and apply with git apply or patch.
The comparison uses a longest-common-subsequence diff with the shared prefix and suffix trimmed first, so only the region that actually differs is analysed. Hunks merge when changes fall within twice the context radius, exactly as GNU diff does, and zero-length sides get the correct line numbers.
You can set the context radius from 0 to 20 lines, ignore whitespace changes, ignore case, and name both sides so the headers match your files. Added, removed and unchanged line counts are shown, and everything runs locally in your browser.
Frequently asked questions
What is a unified diff?
It is the standard patch format used by git and diff -u. Each changed region becomes a hunk introduced by a @@ header giving the line ranges, followed by context lines prefixed with a space, removals with a minus and additions with a plus.
How do I apply the generated patch?
Save it as a .patch file and run git apply changes.patch from the repository root, or patch -p1 < changes.patch outside git. Make sure the file names in the headers match the real paths, adjusting the -p level if they do not.
What do the numbers in the @@ header mean?
They are the starting line and length of the hunk in each file, so @@ -12,7 +12,9 @@ means seven lines starting at line 12 of the original become nine lines starting at line 12 of the new version. A length of 1 is written without the comma.
How many context lines should I use?
Three is the default for git and diff, and it is enough for patch tools to locate the change even if surrounding lines have shifted slightly. Use more for heavily edited files, or zero when you only want to see the changed lines themselves.
Why does it say the texts are too large to compare?
The algorithm builds a table proportional to the number of differing lines on each side, and that is capped to keep the page responsive. Trim the inputs or compare a smaller section — files that are similar stay fast regardless of length, because the shared prefix and suffix are skipped.
Is my text uploaded to compare it?
No. The diff is computed entirely in your browser, so it is safe to compare configuration files, source code or anything else you would not want to paste into an online service.
Related tools
Text Compare
Compare two texts online free and highlight every difference. A private text comparison tool that finds matches and changes right in your browser.
Changelog Generator
Turn a list of Conventional Commits into a Keep a Changelog release entry. Groups feat, fix, perf and revert into sections and flags breaking changes.
CSV Diff
Compare two CSV files online and see added, removed and changed rows. Match on a key column or by row position, with a downloadable change report.
JSON Diff
Compare two JSON documents structurally and see added, removed and changed values by path, ignoring key order. Free online JSON diff, 100% in your browser.