Patchwork is the code transformation platform that takes a diff and applies it to the original with zero guesswork. Hunks, offsets, fuzz factors β resolved in milliseconds. The future of controlled code evolution.
Patchwork ships with the most surgical code transformation engine ever built. Apply changes from any diff source β context, unified, normal β with intelligent fuzz matching and conflict resolution.
patch < DIFF
Feed any diff β from stdin, piped email, GitHub PRs, or raw files. Patchwork auto-detects the format, skips leading garbage, handles CRLF, RFC 934 encapsulation, and indented diffs. Just pipe and apply.
-p NUM
Strip the smallest prefix containing NUM leading slashes from each filename. Essential when
applying patches across directory structures that don't match the sender's. -p1 is
the industry standard.
--dry-run
See exactly what will happen before making a single change. Full simulation of the patch application β hunk status, offsets, conflicts β without touching a file. The safety net every engineer needs.
-R
Undo any patch by swapping old and new. Because sometimes the future wasn't ready. Patchwork even auto-detects reversed patches: if the first hunk fails, it tries the reverse heuristic before giving up.
-b -V STYLE
Never lose the original. Choose simple (.orig), numbered (.~N~), or
existing-style backups. Customize prefix, suffix, and basename prefixes for total control over
your safety copies.
-F NUM
When context doesn't match exactly, Patchwork scans forward and backward with configurable fuzz. Ignore 1, 2, or more lines of context to find where the hunk really belongs. Default: 2. Surgical, not brittle.
--merge
Conflicts don't have to be fatal. Patchwork merges hunks directly into originals using
<<<<<<< / ======= /
>>>>>>> markers β just like your version control. Choose diff3
or merge format output.
-c / -u / -n
Auto-detect context, unified, normal, or ed script formats. Or force the parser with flags. Patchwork speaks every diff dialect β from legacy ed scripts to modern unified, and everything in between.
Feed Patchwork a diff from any source β stdin pipe, file with -i FILE, or positional
argument. Works with unified, context, normal, and ed formats. Skips email headers, RFC
encapsulation, and comments automatically.
Each hunk is matched against the target file. Patchwork checks line numbers, applies fuzz
(-F), handles offsets, and scans forward/backward for the best insertion point.
Conflicts are captured, not ignored.
The patched version replaces the original (or goes to -o FILE). Backups
(-b) are created per your versioning policy. Rejected hunks go to .rej
files. Empty files get cleaned up with -E.
Paste an original file and a unified diff. Watch Patchwork transform it in real time.
Click "Apply Patch" to see the result...
Our merge engine brackets conflicts with standard markers. Resolve inline, accept theirs, keep yours β all from a single interface.
--dry-run simulates every hunk, every offset, every fuzz match β without writing a
single byte.
$ patchwork --dry-run -p1 < update.patch
checking file src/config.yml...
Hunk #1 succeeded at 12 (offset 3 lines).
Hunk #2 succeeded at 45.
Hunk #3 succeeded at 78 with fuzz 1.
checking file src/server.js...
Hunk #1 succeeded at 1.
Hunk #2 FAILED at 34.
checking file README.md...
Hunk #1 succeeded at 1.
---
3 files would be patched
5 of 6 hunks would succeed
1 hunk would FAIL β saved to src/server.js.rej
"We apply 400+ patches per deploy cycle. Patchwork's fuzz intelligence means we spend
zero time debugging misaligned hunks. The -F 2 default is chef's kiss β perfect
balance of flexibility and precision."
"The --dry-run feature alone justified our entire migration to Patchwork.
We preview every patch before applying and catch offset drift before it becomes a production
incident. Absolute game changer."
"Patchwork's merge mode with conflict markers saved our team from writing custom merge
tooling. We pipe diffs from six upstream repos, resolve inline, and ship.
--merge=diff3 is the unsung hero."
"I maintain a kernel fork and apply hundreds of patches with -p1 from
mailing lists. Patchwork strips email headers, handles CRLF, and just works. I haven't manually
resolved a reject file in months."
Start free. Upgrade when your transformation workflows demand more.
-p NUM stripping-c -u -n--dry-run-R-b -V-F NUM--merge-l$ patchwork -p1 < feature.patch
patching file src/auth.js
Hunk #1 succeeded at 12 (offset 2 lines).
Hunk #2 succeeded at 45.
patching file src/config.yml
Hunk #1 succeeded at 8 with fuzz 1.
$ patchwork -R -b -V numbered -p1 < feature.patch
patching file src/auth.js
Hunk #1 succeeded at 12 (offset 2 lines).
Hunk #2 succeeded at 45.
backup: src/auth.js β src/auth.js.~1~
$ patchwork --dry-run -p1 -i hotfix.patch
checking file server.conf...
Hunk #1 succeeded at 1.
Hunk #2 FAILED at 24.
1 out of 2 hunks FAILED β saving rejects to server.conf.rej
$ patchwork -d /usr/src/app --merge -p1 < upstream.patch
patching file api/routes.js
1 conflict in api/routes.js
Patchwork handles unified (-u), context (-c), normal (-n),
and ed script (-e) formats. It auto-detects the format from the input, or you can
force it with flags. Unified is the most common format used by git, GitHub, and modern tooling.
Context diffs include surrounding lines for better matching.
When a hunk can't be applied at its target location, Patchwork scans forward and backward using
the fuzz factor (-F NUM, default 2). If still no match, the hunk is saved to a
.rej reject file (customizable with -r FILE) and the rest of the patch
continues applying. You're told exactly which hunk failed and where.
The fuzz factor controls how many lines of context Patchwork ignores when searching for hunk placement. At fuzz 0, all context must match exactly. Fuzz 1 ignores the first and last context lines. Fuzz 2 (default) ignores the first two and last two. Higher fuzz is more flexible but increases risk of misplacing hunks.
Yes β use -o FILE to write the patched output to a different file, or
--dry-run to simulate without writing anything at all. You can also use
-b to create automatic backups before any changes are made. The backup style
(simple, numbered, or existing) is controlled via -V.
-p1 actually do?The -p flag strips leading path components from filenames in the patch. Given a path
like /u/dev/src/app/config.js, -p0 keeps the full path,
-p1 removes the leading slash giving u/dev/src/app/config.js,
-p4 gives app/config.js. This is essential when directory structures
differ between sender and receiver.
Patchwork processes everything locally. No files are uploaded, no telemetry is collected on content, and no cloud services are required. Enterprise customers deploy fully on-prem with SOC 2 compliance. Your code never leaves your infrastructure.