{
  "slug": "apply-patch",
  "name": "gizza-ai/apply-patch",
  "version": "0.1.0",
  "title": "Apply Patch Online — Apply a Unified Diff to a File — gizza.ai",
  "description": "Paste a file and a unified diff to get the patched text in your browser, with reverse apply, fuzz matching, and per-hunk conflict reports.",
  "tags": [
    "apply patch",
    "unified diff",
    "git apply",
    "patch file online",
    "reverse patch",
    "patch conflicts",
    "rejected hunks"
  ],
  "category": "developer",
  "urls": {
    "page": "https://gizza.ai/tools/apply-patch/",
    "markdown": "https://gizza.ai/tools/apply-patch/index.md",
    "descriptor": "https://gizza.ai/tools/apply-patch/tool.json",
    "deep_link_example": "https://gizza.ai/tools/apply-patch/?source=fn%20main%28%29%20%7B%0A%20%20%20%20let%20x%20%3D%201%3B%0A%20%20%20%20println%21%28%22%7Bx%7D%22%29%3B%0A%7D&patch=---%20a%2Fsrc%2Fmain.rs%0A%2B%2B%2B%20b%2Fsrc%2Fmain.rs%0A%40%40%20-1%2C4%20%2B1%2C5%20%40%40%0A%20fn%20main%28%29%20%7B%0A%20%20%20%20%20let%20x%20%3D%201%3B%0A%2B%20%20%20%20let%20y%20%3D%202%3B%0A%20%20%20%20%20println%21%28%22%7Bx%7D%22%29%3B%0A%20%7D&output=patched&reverse=true&fuzz=2&ignore_whitespace=true&on_conflict=fail&file=src%2Fmain.rs"
  },
  "cli": "gizza tool apply-patch 'fn main() {\n    let x = 1;\n    println!(\"{x}\");\n}' 'patch=--- a/src/main.rs\n+++ b/src/main.rs\n@@ -1,4 +1,5 @@\n fn main() {\n     let x = 1;\n+    let y = 2;\n     println!(\"{x}\");\n }'",
  "tool": {
    "description": "Apply a unified diff / git patch to a pasted source file and return the patched text. Pass source (the file as it is now) and patch (the diff). output='patched' (default) returns the patched file; 'report' is a dry run listing every hunk with the line it landed on, its offset, the fuzz used, or why it failed; 'json' returns that as data plus the patched text; 'rejects' returns the failed hunks as a standalone patch. reverse=true unapplies the patch (git apply -R) to recover the original. fuzz (0-3, default 2) is how many context lines may be dropped from each end of a hunk when the exact context drifted; ignore_whitespace=true matches context ignoring indentation changes while keeping the source's own whitespace in the output. on_conflict='fail' (default) refuses the patch and names the expected vs found line; 'skip' applies what matches. file picks one path out of a multi-file patch. Hunks may land away from the line their @@ header claims (offset search); wrong @@ counts are recounted; CRLF, the source's final-newline state and '\\ No newline at end of file' are preserved. 1 MB cap per input. Binary, rename-only, and combined (@@@) diff entries are reported as unsupported, not silently dropped.",
    "parameters": {
      "additionalProperties": false,
      "properties": {
        "file": {
          "default": "",
          "description": "Which file's hunks to apply when the patch touches more than one — a full path ('src/main.rs'), a bare filename ('main.rs'), or any substring of the path. Blank (default) works when the patch touches exactly one file; a multi-file patch with no filter reports the paths it found instead of guessing.",
          "type": "string"
        },
        "fuzz": {
          "default": 2,
          "description": "How many CONTEXT lines may be dropped from each end of a hunk when an exact match fails — the `patch -F` fuzz factor. 0 requires every context line to match; 2 (default, same as `patch(1)`) tolerates a couple of drifted surrounding lines; 3 is the maximum. Fuzz never drops a '+' or '-' line and never reduces a hunk to zero context, so it cannot turn a real conflict into a blind insertion.",
          "maximum": 3,
          "minimum": 0,
          "type": "integer"
        },
        "ignore_whitespace": {
          "default": false,
          "description": "Match context and deleted lines with runs of whitespace collapsed and the ends trimmed, like `git apply --ignore-whitespace` — use it when the source was reindented (tabs vs spaces) since the patch was made. Matching only: context lines are re-emitted with the SOURCE file's own whitespace, byte for byte. Default false.",
          "type": "boolean"
        },
        "on_conflict": {
          "default": "fail",
          "description": "What to do when a hunk does not match, for output='patched'. 'fail' (default) refuses the whole patch and names the hunk, the line it expected and the line it found, so you never get a half-applied file by accident. 'skip' applies every hunk that matches and leaves the rest out, like `patch --reject` — pair it with output='rejects' to get the leftovers as a patch.",
          "enum": [
            "fail",
            "skip"
          ],
          "type": "string"
        },
        "output": {
          "default": "patched",
          "description": "What to return. 'patched' (default) is the patched file text. 'report' is a dry run like `git apply --check`: one line per hunk with the line it landed on, the offset from its header, the fuzz used, or why it failed. 'json' is the same data as machine-readable fields plus the patched text. 'rejects' returns only the hunks that did NOT apply, as a standalone patch you can fix by hand. 'report' and 'json' never fail on a conflict — they describe it.",
          "enum": [
            "patched",
            "report",
            "json",
            "rejects"
          ],
          "type": "string"
        },
        "patch": {
          "description": "The unified diff to apply — the output of `git diff`, `git show`, `git format-patch`, `diff -u`, or `svn diff`, including its `@@` hunk headers. `---`/`+++`/`diff --git` file headers are optional; wrong `@@` line counts are recounted from the body. Max 1000000 bytes (1 MB).",
          "type": "string"
        },
        "reverse": {
          "default": false,
          "description": "Apply the patch backwards, like `git apply -R` / `patch -R`: '+' and '-' swap roles so the change is undone. Use this to recover the original file from a patched one, or to revert a commit's diff. Default false.",
          "type": "boolean"
        },
        "source": {
          "description": "The original file text the patch applies to — paste the file as it is right now, before the change. Its line endings (LF or CRLF) and final-newline state are preserved in the result. Max 1000000 bytes (1 MB). Pass an empty string when the patch creates a new file.",
          "type": "string"
        }
      },
      "required": [
        "source",
        "patch"
      ],
      "type": "object"
    }
  }
}