Patch Applier

Apply a unified-diff .patch to your source text right in the browser.

Free in-browser patch applier. Paste a unified-diff patch and the original source, and the tool applies each hunk, shows the patched result, and reports any hunks that did not match. No file access; everything runs locally and nothing is uploaded. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What patch format does this accept?

Standard unified diffs as produced by git diff or diff -u: optional --- / +++ file headers followed by @@ -a,b +c,d @@ hunks whose lines are prefixed with a space (context), minus (removed) or plus (added).

A unified-diff patch describes a change as a set of hunks, each one a window of context lines plus the lines to remove (-) and add (+). The Patch Applier takes such a patch and your original text and produces the patched output in your browser — useful for applying a shared diff when you do not have a checkout to run git apply against.

How it works

  1. The patch is parsed into hunks: each @@ -a,b +c,d @@ header starts a new hunk, and the following , -, + lines are collected.
  2. For each hunk, the tool builds the expected old block (context + removed lines) and the new block (context + added lines).
  3. It looks for the old block at the header’s line number; if that does not match exactly, it searches nearby lines for the same block (fuzzy location), so a small drift in the file still applies.
  4. On a match it splices in the new block; on no match the hunk is rejected and the original lines are kept.

Example

Applying this hunk:

@@ -1,3 +1,3 @@
 .btn {
-  color: red;
+  color: blue;
 }

to a source whose first lines are .btn { / color: red; / } yields the same block with blue instead of red.

Notes

Hunks are applied independently, so a partly-stale patch still lands the hunks that match while clearly flagging those that do not. Line endings are normalised to \n during matching. Everything runs locally — your source and patch never leave the browser.