Apply a patch with fuzz and offset, and see every hunk's status

Paste a unified diff and the original text. Get the patched text and a status for every hunk: exact, offset, fuzz or failed, with the reason.

How it works

  1. Paste the unified diff in the first box and the original text in the second
  2. Set the search distance and fuzz, or leave the defaults of 200 lines and 2
  3. Copy the patched text and read the status of each hunk

How a hunk is applied

To apply a unified diff to text, the tool finds each hunk's context and removed lines in your text and swaps in the new lines. A hunk is one block that starts with a line like @@ -3,5 +3,6 @@, which says the block begins at line 3 of the old text and covers 5 lines. The tool looks for the hunk at that line first. If the lines are not there, it checks 1 line later, 1 line earlier, 2 lines later and so on, up to the search distance you set, and uses the nearest match. The distance it moved is the offset. Worked example: the hunk @@ -1,3 +1,3 @@ with the context lines one and three around a change of two to TWO is applied to a text that has two extra lines at the top. It is found 2 lines later, so the status is Applied with offset +2.

Fuzz and whitespace

Fuzz, a number from 0 to 3, lets that many context lines at the start and at the end of a hunk differ, which is what the patch program's fuzz factor does. The lines that are removed must always match, so a fuzzy match can only be wrong about the surroundings, not about what it deletes. The default here is 2, and the status column shows the fuzz that was needed, so a hunk that needed fuzz 1 is easy to spot and check. The option Ignore whitespace differences compares lines after treating each run of spaces and tabs as one space and trimming the ends, which helps when a diff was copied from a chat window that changed the indentation. Line endings are handled too. CRLF and LF diffs apply to CRLF or LF text, each original line keeps its own ending, and added lines use the ending most lines of the original have, or the one you choose.

When a hunk fails

A hunk fails when its removed lines and context are not found within the search distance, even with fuzz. The table gives the reason in plain words. Context found farther away is reported with the distance to set, such as: the context matches 40 lines later, set the search distance to at least 40. A hunk whose result is already in the text is reported as already applied, and the Apply in reverse option undoes a diff. A hunk that needs lines an earlier hunk already used is reported as overlapping. The Failed hunks box shows the first line that did not match, with what the diff expects and what the text has. By default the hunks that fit are applied and the failed ones are skipped. Choose Apply nothing to get a result only when every hunk fits.

What it does not do

This tool applies text hunks to one pasted text. If the diff covers several files, only the first file with hunks is applied, and a notice says so. It does not apply binary patches, renames or file mode changes, and it does not check that the result compiles or passes tests. A diff written by an AI model often has wrong line numbers or header counts; a header that disagrees with its body is reported and the body is used. If the body itself is wrong, for example a context line that was never in your file, no setting can find it, and the Failed hunks box shows which line to correct.

Frequently asked questions

How do I apply a unified diff without git?

Paste the diff in the first box and the file's current text in the second. The Patched text box shows the result and the table shows how each hunk went. For a diff made by git diff or diff -u, the --- and +++ lines may be left in or taken out.

What does Hunk #1 succeeded at 12 (offset 3 lines) mean?

It is the patch program's way of saying the hunk was found 3 lines away from the number in its @@ header. Here the same fact is in the Offset column, shown as +3 or -3, and the Reason column spells it out. An offset is harmless when the context matches.

What is the fuzz factor in patch?

Fuzz is the number of context lines at each end of a hunk that may be ignored when matching. Fuzz 2 means up to 2 lines at the top and 2 at the bottom of a hunk can differ. The lines being removed are never ignored. Set fuzz to 0 when you want a strict match only.

Why does my AI-generated diff fail to apply?

Model-written diffs often carry wrong line numbers, a header count that does not match the body, or context lines that were retyped from memory. A wrong number is fixed by the search distance. A retyped context line needs fuzz, and a wrong removed line needs correcting by hand. The Failed hunks box shows the first mismatch.

How do I undo a patch?

Paste the same diff and the patched text, then turn on Apply in reverse. Added lines are treated as removed and removed lines as added, so a diff that changed one to TWO now changes TWO back to one.

Is my text uploaded?

No. It is processed in your browser, in this tab, and no server receives it. Your search distance, fuzz and other options are saved in this browser, the diff and the text are not.