Git Unified Diff & Patch Generator
Guide
Git Unified Diff & Patch Generator
Paste an original snippet and a modified snippet to instantly generate a valid unified diff in .patch format. The output uses correct hunk headers (@@ -L,N +L,N @@) so the patch applies cleanly with git apply or the standard patch utility — no hand-fixing required.
How to Use
- Paste the original text into the Original textarea.
- Paste the modified version into the Modified textarea.
- Optionally adjust the Original Path and Modified Path to set the filenames used in the
---and+++headers. - Drag the Context Lines slider to choose how many unchanged lines surround each change (0–10).
- Copy the unified diff or download it as
changes.patchfor use withgit applyorpatch -p1.
Features
- Standards-compliant unified diff – correct hunk headers, line counts, and context handling.
- Configurable context – choose 0 to 10 surrounding context lines per hunk.
- Custom file paths – set the
a/andb/filenames so the patch targets the right file. - Stat summary – instant +N / -N readout of added and removed lines.
- One-click download – export the patch as
changes.patch, ready forgit apply. - Runs entirely in your browser – nothing is uploaded; works offline once the page is loaded.
When to Use This Tool
Reach for this generator whenever you need to share a code change as a patch — for example, when posting on an issue tracker, mailing a contribution, or pasting AI-suggested edits into a real codebase. It is especially useful for converting LLM “before / after” snippets into a patch you can actually apply with one command.
FAQ
-
What is a unified diff?
A unified diff is the standard text format for describing changes between two files. It begins with two header lines (--- old and +++ new) followed by one or more hunks. Each hunk starts with @@ -oldStart,oldCount +newStart,newCount @@ and lists context, removed (-), and added (+) lines. The format was popularized by the GNU diff utility and is the format git apply and patch expect by default.
-
How does git apply use a unified diff?
git apply reads a unified diff and replays each hunk against the matching file in the working tree. It uses the hunk's line numbers and surrounding context to locate the change site, then performs the additions and removals. If the context does not match (because the target file has drifted), git apply rejects the patch unless you pass options such as --3way or --reject.
-
What do the numbers in @@ -1,5 +1,6 @@ mean?
The hunk header tells you where the change lives and how many lines it spans on each side. -1,5 means the original file segment starts at line 1 and covers 5 lines (the deleted plus context lines). +1,6 means the new file segment starts at line 1 and covers 6 lines (the added plus context lines). When the count is 1, the comma and number are sometimes omitted (for example, @@ -42 +42 @@).
-
Why do extra context lines matter in a patch?
Context lines are the unchanged lines printed above and below each change. They give the patch tool an anchor for finding the change in the target file, even if the surrounding code has shifted by a few lines. More context (for example 5 or 7 lines) makes a patch more resilient to small drift but also makes it larger; the GNU diff default of 3 lines is usually a good balance.
Install Our Extensions
Add IO tools to your favorite browser for instant access and faster searching
恵 Scoreboard Has Arrived!
Scoreboard is a fun way to keep track of your games, all data is stored in your browser. More features are coming soon!
Must-Try Tools
View All New Arrivals
View AllUpdate: Our latest tool was added on Apr 29, 2026
