Reverse a Unified Diff

Paste a git or unified diff and get the inverse patch back — hunks, paths, index hashes, renames, mode changes, and no-newline markers handled locally.

Try:
Reverse patch

About this tool

A reverse patch is the text you would apply to undo a change. Paste the output of git diff, git show, git format-patch, diff -u, or a bare unified hunk, and this tool emits the inverse patch: old and new hunk ranges swap, + lines become -, - lines become +, and git metadata is flipped so the result behaves like a revert.

Worked example — given this patch:

diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
 fn main() {
+    println!("hello");
 }

the default output is:

diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,3 @@
 fn main() {
-    println!("hello");
 }

Save that output and apply it with your usual patch tool to remove the line. Nothing is applied here; the tool only rewrites the patch text.

Git headers it understands

Real diffs are more than @@ hunks. The reverse operation also handles the metadata that makes a patch apply cleanly:

Output modes

Use File filter for a multi-file patch: full path, suffix on a directory boundary, or bare filename all match. Leave it blank to reverse every file section.

Limits and edge cases

FAQ

Is this the same as `git apply -R`?

No. git apply -R applies a forward patch backwards to files in a working tree. This tool emits a new reverse patch as text. You can inspect, save, edit, or apply that patch yourself.

Why do index lines have swap, keep, and drop modes?

git diff -R swaps index old..new to index new..old, which is the default here. Keeping is useful for tools that treat those lines as annotations only. Dropping is safest when the patch is detached from the repository that produced the blob hashes.

Can it revert a binary patch?

Not from the forward patch alone. A GIT binary patch contains a delta in one direction, not enough information to synthesize the opposite delta. The tool fails by default so you do not mistake an incomplete reverse patch for a full revert.

What if I only want one file from a multi-file diff?

Put a path in File filter. It matches an exact path, a suffix such as src/main.rs, or a basename such as main.rs. The output contains only matching file sections.

Will this fix a patch that no longer applies?

No. Inversion is byte-exact; it does not search a working tree or tolerate drifted context. If you need fuzzy matching, conflict reports, or reverse-applying to pasted source text, use an apply-patch tool after generating or selecting the right patch.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool unified-diff-reverse 'diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,3 +1,4 @@
 fn main() {
+    println!("hello");
 }'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/unified-diff-reverse/?diff=diff%20--git%20a%2Fsrc%2Fmain.rs%20b%2Fsrc%2Fmain.rs%0A---%20a%2Fsrc%2Fmain.rs%0A%2B%2B%2B%20b%2Fsrc%2Fmain.rs%0A%40%40%20-1%2C3%20%2B1%2C4%20%40%40%0A%20fn%20main%28%29%20%7B%0A%2B%20%20%20%20println%21%28%22hello%22%29%3B%0A%20%7D&output=patch&file=src%2Fmain.rs&index_lines=swap&swap_paths=true&on_binary=fail

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.