Diff Patch Generator

Generate a unified diff or git-style patch between two pieces of text. Tune context lines, file names, and whitespace handling, then copy or download a ready-to-apply .patch file.

Patch Options

Generated Patch

+4 added -3 removed 1 hunk
Index: a/greet.js
===================================================================
--- a/greet.js
+++ b/greet.js
@@ -1,5 +1,6 @@
-function greet(name) {
-    console.log("Hello, " + name + "!");
+function greet(name = "world") {
+    console.log(`Hello, ${name}!`);
 }
 
-greet("world");
+greet();
+greet("everyone");

Inline Preview

A line-level view of the change set — green for additions, red for deletions.

-function greet(name) {
- console.log("Hello, " + name + "!");
+function greet(name = "world") {
+ console.log(`Hello, ${name}!`);
 }
 
-greet("world");
+greet();
+greet("everyone");

About Diff Patch Generator

A patch is a text file describing how to transform one piece of text into another. The unified diff format — diff -u in Unix and the default in Git — shows additions with a leading +, deletions with -, and surrounding context lines for orientation. Each change is grouped into a hunk with a header like @@ -1,4 +1,6 @@ indicating start lines and counts on each side.

This generator takes two text blobs (original / modified), runs a Myers-style line diff under the hood (via the jsdiff library), and emits a unified diff or a Git-style patch with diff --git and an index line. The output is ready to feed to patch, git apply, or any review tool that reads unified diffs.

Everything runs in your browser — your text never leaves the page.

How to Use Diff Patch Generator

  1. Paste the Original text on the left and the Modified text on the right.
  2. Use Swap sides if you have them the wrong way around.
  3. Set the file names shown in the patch header. The convention is a/path for old and b/path for new.
  4. Pick the number of context lines shown around each change (3 is the standard).
  5. Choose the format: plain unified diff (works with patch -p0 or patch -p1) or git-style (works with git apply).
  6. Toggle Ignore whitespace or Ignore case for noisier inputs.
  7. Use the Inline Preview below to sanity-check the changes line by line.
  8. Click Copy to grab the patch or Download .patch to save it as a file.

Common Use Cases

Code review snippets

Turn two pasted code blocks into a shareable patch for a PR comment or Slack message.

Bug reports

Show maintainers the exact change you made, in a format they can apply with one command.

Config drift

Diff two versions of a config file (Nginx, Apache, docker-compose, Kubernetes manifest) and ship the result as a patch.

Generating fixtures

Produce sample patches for testing patch parsers, code-review UIs, or AI pipelines.

Doc edits

Show before/after for documentation changes that should be reviewed but are not in version control yet.

Distributing fixes

Hand a non-developer a small .patch file to apply locally without rolling a full release.

FAQ

How do I apply the generated patch?

Save the output as changes.patch, then run either patch -p1 < changes.patch (classic Unix) or git apply changes.patch in a Git working tree. The -p1 flag strips the leading a/ or b/ from the file paths.

What is the @@ -1,4 +1,6 @@ line?

It is the hunk header. It tells patch where in each file the next block of changes lives: in the old file the hunk starts at line 1 and is 4 lines long; in the new file it starts at line 1 and is 6 lines long.

When should I use the Git-style format?

Pick Git-style when the patch will be applied with git apply, sent via git am, or pasted into Gerrit / GitHub. It adds the diff --git a/... b/... and index ... lines that Git uses to identify the file and blob hashes. The index hashes in this tool are short fingerprints, not real Git object hashes — Git will recompute them on apply, which is fine for textual content.

How many context lines should I use?

Three is the default for a reason — it is enough for most patches to apply cleanly even when surrounding code has shifted slightly. Use more (5–7) when patches must survive lots of unrelated edits, or fewer (0–1) when you want the smallest possible diff for readability.

What does "Ignore whitespace" do?

It tells the diff algorithm to treat lines as equal if they only differ in whitespace. Useful when comparing reformatted code, but the resulting patch will still contain the literal lines from each side — it just won't mark whitespace-only changes as additions or deletions.

Is my text sent to a server?

No. The diff is computed locally using the diff package shipped with the page bundle. Nothing is uploaded, logged, or stored anywhere.