Git Diff ↔ Patch File Converter

Convert raw git diff output to downloadable .patch files or compare code snippets to generate patches 100% client-side. Find common git diff commands.

DomainProgrammingVersionv1.0.0Added2026-05-26

Generate, visualize, and download git patch files with zero backend dependencies. Paste raw diff output to output a standardized .patch file, compare two text blocks to calculate a unified diff, and copy common git commands to apply patches.

01
Select Mode
02
Paste Raw Git Diff
POST /v1/programming-dev/git-diff-to-fileView API docs →
curl -X POST https://toolsamurai.com/api/v1/programming-dev/git-diff-to-file \
  -H "Authorization: Bearer sk_live_•••••••••••••••" \
  -H "Content-Type: application/json" \
  -d '{
     "mode": "paste",
     "raw_diff": "diff --git a/app.js b/app.js\nindex e69de29..c307c86 100644\n--- a/app.js\n+++ b/app.js\n@@ -1,4 +1,4 @@\n-const port = 3000;\n+const port = 3001;\n const host = \"localhost\";\n \n-console.log(\"Running on \" + host + \":\" + port);\n+console.log(`App serving on http://${host}:${port}`);",
     "before_code": "function add(a, b) {\n  return a + b;\n}",
     "after_code": "/**\n * Adds two numbers together.\n */\nfunction add(a, b) {\n  if (typeof a !== 'number' || typeof b !== 'number') {\n    throw new TypeError('Arguments must be numbers');\n  }\n  return a + b;\n}",
     "file_path": "math.js"
  }'
gitdiffpatchcode-compareunified-diffdeveloper-tools
How it works

The method behind the numbers

This tool runs completely client-side in your browser. When comparing snippets, it uses a standard Myers-based diff algorithm to compute the shortest edit script and formats it into the standard unified diff header representation. When parsing pasted diffs, it reads the hunks and counts modifications to compile changed-file statistics, which let you see total line insertions and deletions at a glance.

Worked examples

See it in practice

Convert snippet change to patch

Compare a simple function change and get a unified patch format.

mode
compare
before_code
function greet() { return 'hello'; }
after_code
function greet() { return 'hello world!'; }
file_path
greet.js
FAQ

Frequently asked questions

How do I save a diff directly from my terminal?

You can pipe the git diff command straight into a file. E.g., run `git diff > my_changes.patch` to save all unstaged modifications in your current working directory.

How do I apply a patch file back into git?

To apply a `.patch` or `.diff` file to your codebase, run `git apply name_of_patch.patch`. If you want to apply it as a commit with its author/metadata, use `git am < name_of_patch.patch`.

Is my code sent to any servers?

No. The diffing, patch generation, and parsing are performed entirely client-side using JavaScript in your browser. None of your code snippets or diff inputs are uploaded to our servers, making it 100% secure for private keys or confidential files.

Embed

Put Git Diff ↔ Patch File Converter on your site

Free, no signup required. Customise theme, pre-fill values, or lock inputs so visitors can only change what you choose.

Leave a field blank to keep its built-in default. Tick 🔒 to lock it read-only in the embed.
<iframe src="https://toolsamurai.com/embed/programming-dev/git-diff-to-file"
        width="100%" height="640" frameborder="0"
        style="border:0;display:block"
        title="Git Diff ↔ Patch File Converter — ToolSamurai"></iframe>
Live preview
Read the embed docs →