← Back to tool

Hunks · Context · Patch

Unified Diff Online

Updated: June 2026

A unified diff is the lingua franca of change. It is what git diff prints, what pull requests render, and what patch applies. When you have two versions of a text but no repository between them, this tool generates that same format on demand — paste the before and after, and get a clean, copy-ready patch.

Generate a Unified Diff →

Free · No upload · Copy or download .diff

Reading the format

A unified diff is made of hunks. Each hunk starts with a header that tells you where the change sits in both files, followed by the changed region with one line of context before and after:

--- original
+++ changed
@@ -3,4 +3,5 @@
 unchanged context line
-this line was removed
+this line was added
+and so was this one
 trailing context line

The header @@ -3,4 +3,5 @@ means: starting at line 3 the original had 4 lines, and starting at line 3 the changed version has 5. A space prefix marks context, - marks a deletion and + marks an addition. That is the whole format — compact, unambiguous and universally understood by tooling.

How this generator works

  • Paste the original text in the left panel and the new text in the right.
  • The tool computes the line-level differences with a longest-common-subsequence engine.
  • It groups nearby changes into hunks, keeping three lines of context around each.
  • Click Copy unified diff or Download .diff to take the patch.

Identical inputs produce no hunks, exactly like running diff on two identical files. The context count of three lines matches the default of git and GNU diff, so the output looks and behaves like the diffs you already read every day.

What you can do with the patch

UseHow
Pull request commentPaste the diff in a fenced code block for reviewers
Apply a changeSave as .diff and run git apply or patch < file.diff
Bug reportAttach the exact change that reproduces an issue
DocumentationShow a before/after edit in a guide or changelog

If you need to apply the patch with git apply, replace the --- original / +++ changed headers with the real file paths; the hunk bodies are already in the correct form.

Runs entirely in your browser

The diff is computed locally with JavaScript, so neither version of your text is sent to a server. That keeps source code, configuration and private documents on your own machine while still giving you a standards-compliant patch you can paste anywhere. Once loaded, the generator keeps working offline.

Frequently asked questions

What is a unified diff?

A unified diff is the standard patch format used by git and diff -u. It lists changes as hunks headed by @@ -a,b +c,d @@ markers, with removed lines prefixed by - and added lines prefixed by +, plus a few lines of surrounding context.

Can I apply the diff as a patch?

The exported diff uses the same syntax as a git patch. With matching file headers it can be applied using git apply or the patch command, and it pastes cleanly into pull request reviews.

How much context is included?

Three lines of unchanged context are kept around each change and nearby changes are grouped into a single hunk, exactly as standard diff tools do.