Apply a patch
Apply a unified diff to a text and get the patched result, with clear errors when a hunk does not fit.
Input
Result
Fill in the input and press Run.
Your input is processed in memory and then discarded. It is not stored or logged. Even so, don't paste live passwords or keys into any online tool.
Use it from code or an agent
curl -s https://setget.net/v1/tools/patch-apply \
-H 'Content-Type: application/json' \
-d '{"input":{"text":"apple\nbanana\ncherry\n","patch":"--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n"}}'
import json, urllib.request
body = {'input': {'text': 'apple\nbanana\ncherry\n', 'patch': '--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n'}}
request = urllib.request.Request("https://setget.net/v1/tools/patch-apply", json.dumps(body).encode(),
{"Content-Type": "application/json"})
print(json.load(urllib.request.urlopen(request))["result"])
const response = await fetch("https://setget.net/v1/tools/patch-apply", {
method: "POST",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({"input":{"text":"apple\nbanana\ncherry\n","patch":"--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n"}}),
});
console.log((await response.json()).result);
Tool: run_tool
Arguments:
{
"slug": "patch-apply",
"input": {
"text": "apple\nbanana\ncherry\n",
"patch": "--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n"
}
}
{
"input": {
"text": "apple\nbanana\ncherry\n",
"patch": "--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n"
}
}
Endpoint: POST /v1/tools/patch-apply. Over MCP: run_tool with slug: "patch-apply".
Machine-readable: input schema, Markdown. Connect an agent.
Inputs
| Name | Type | Required | What it does |
|---|---|---|---|
text |
string | yes | The original text to change. |
patch |
string | yes | A unified diff for one file. |
Examples
Input
{
"text": "apple\nbanana\ncherry\n",
"patch": "--- before\n+++ after\n@@ -1,3 +1,4 @@\n apple\n-banana\n+blueberry\n cherry\n+date\n"
}Result
{
"text": "apple\nblueberry\ncherry\ndate\n",
"hunks": 1,
"added": 2,
"removed": 1
}A patch without file headers
Input
{
"text": "one\ntwo\n",
"patch": "@@ -2 +2 @@\n-two\n+2\n"
}Result
{
"text": "one\n2\n",
"hunks": 1,
"added": 1,
"removed": 1
}Questions
- What if the line numbers in the patch are slightly off?
- Each hunk is first tried at the line its header names. If the text there is different, the nearest place where the hunk fits exactly is used.
- Why does a hunk not match?
- The text is not the version the patch was made from, or the patch lost its leading spaces when it was copied. The error names the hunk and the first line that differs.
- Can it apply a patch for several files?
- No. Apply the part for each file to that file's text.
Related tools
- Text diffCompare two texts line by line and get a unified diff with counts of added and removed lines.
diff - JSON Patch applyApply a JSON Patch (RFC 6902) to a document: add, remove, replace, move, copy and test.
json-patch-apply - Find and replaceReplace every occurrence of a word or phrase in text, exactly as typed, with a count of the changes.
find-replace - Case converterConvert text between lower, UPPER, Title, Sentence, camelCase, PascalCase, snake_case, kebab-case and more.
case-convert - Escape and unescape textEscape or unescape text for HTML, URLs, JSON strings, shell commands, regular expressions and CSV fields.
escape-unescape - Extract emails and URLsPull every email address and web link out of a text, and optionally IPv4 addresses and hashtags.
extract-emails-urls