Unified Diff / Patch Generator

Generate a real, downloadable .patch file from two texts β€” usable with git apply or patch

3
Paste an original and a modified version to generate a patch

About this tool

The Unified Diff / Patch Generator produces a real, standards-format .patch file from two pasted texts β€” the same unified diff format `git diff` and `diff -u` produce, and the same format `git apply` and the `patch` command consume. Paste an original and a modified version, and get back a downloadable patch with proper @@ hunk headers and configurable context lines, rather than just a visual highlight of what changed. The diff itself is computed with a classic LCS (longest common subsequence) line-diff algorithm β€” the same category of algorithm underlying most real diff tools β€” then grouped into hunks with surrounding context lines, exactly like a real diff utility would produce. This is a genuinely different tool from a visual diff checker: the output here is meant to be applied, not just read.

When to use it

  • β†’Generating a .patch file to share a small fix without opening a pull request
  • β†’Producing a reviewable patch from a config file change made outside version control
  • β†’Understanding exactly what a unified diff's @@ hunk header numbers mean
  • β†’Creating a patch to apply the same textual change across multiple environments

Tips

  • β—†Increase context lines if you plan to git apply this patch against a slightly different version of the file β€” more surrounding context makes the patch more likely to apply cleanly.
  • β—†The file name fields (a/file.txt, b/file.txt) become the --- and +++ lines in the patch β€” set them to match your real file paths if you intend to actually apply this patch.
  • β—†A patch this tool generates against text extracted from a real file should apply cleanly with git apply patchfile.patch or patch -p1 < patchfile.patch, provided the original text truly matches.

Frequently asked questions

What do the numbers in the @@ -3,7 +3,9 @@ hunk header mean?

They're (starting line, line count) pairs for the old and new file respectively. @@ -3,7 +3,9 @@ means this hunk starts at line 3 in the original file and spans 7 lines there, while in the new file it also starts at line 3 but spans 9 lines (because the hunk added 2 net lines). Every real diff tool uses this exact same header format.

Can I actually apply this patch with git or the patch command?

Yes β€” the output is standard unified diff format, the same format git apply and patch -p1 (or patch -p0, depending on how the file paths are set) both consume. As long as the target file's content genuinely matches what you pasted as the 'original' text, the patch should apply cleanly.

Why would I use this instead of just running git diff?

git diff requires the text to actually be in a git repository already. This tool is for the case where you have two versions of some text β€” copied from a doc, a config file that isn't in version control, output from two different runs β€” and want a real, applyable patch between them without setting up a repo just to generate one.

Related tools

πŸ₯· ToolNinja