Git Unified Diff Patch Generator
Compare two blocks of text and generate a Git-style unified diff (.patch) with proper @@ hunk headers, using a Myers diff algorithm. Configure context lines and the a/b file paths.
Input
Unchanged lines shown around each change (standard diff -u is 3).
Output
Guides
Paste two versions of a file and get a ready-to-apply unified diff patch — the exact --- a, +++ b, @@ -l,s +l,s @@ format produced by git diff and diff -u. It runs entirely in your browser, so nothing you paste ever leaves your machine.
What is a unified diff?
A unified diff is the standard text format for describing changes between two files. Each patch begins with two header lines naming the original (---) and modified (+++) files, followed by one or more hunks. A hunk starts with a header like @@ -12,7 +12,8 @@ recording the starting line and length on each side, then lists context lines (prefixed with a space), removed lines (-), and added lines (+). It is the format Git stores in commits, that code-review tools render, and that patch and git apply consume.
How to use it
- Paste the original text in the Original box and the changed text in the Modified box.
- Optionally set the Original path and Modified path — these become the
--- a.txt/+++ b.txtheader lines. Use real repository paths (e.g.a/src/index.js) if you plan togit applythe result. - Adjust Context lines if you need more or fewer unchanged lines around each change. The default of 3 matches
diff -u; set it to 0 for the tightest possible patch. - Copy the generated patch or download it as a
.patchfile.
How the diff is computed
The tool uses Myers' O(ND) diff algorithm — the same shortest-edit-script approach Git is built on. Myers finds the minimal set of insertions and deletions that turns the original into the modified text, then groups those edits into hunks with your chosen amount of context. Adjacent changes within twice the context window merge into a single hunk, exactly as diff -u does, so the output is byte-for-byte compatible with standard tooling.
Applying the patch
Save the output as changes.patch, then apply it with git apply changes.patch or patch -p0 < changes.patch. If you used a/… and b/… path prefixes, git apply -p1 maps them onto your working tree.
Is it accurate for code?
Yes. The line-level diff is deterministic and matches GNU diff -u on the same inputs, including hunk headers and line counts. It compares whole lines, so a single changed character shows as one removed line and one added line — the normal behaviour for line-based patches.
Privacy
All processing happens client-side in your browser. Your text is never uploaded, logged, or sent to a server, which makes the tool safe for proprietary source code and other sensitive files.
Frequently asked questions
What context-line count should I use? Three is the universal default and what reviewers expect. Increase it when a patch needs more surrounding code to be readable; drop it to 0 for the most compact diff.
Can I generate a patch for a brand-new or deleted file? Yes — leave one side empty. An empty Original produces an all-additions patch; an empty Modified produces an all-deletions patch.