Diff Patch Generator & Apply Online
Generate unified diff patches from two text versions, or apply an existing patch to reconstruct the modified file. Compatible with git apply and POSIX patch.
What Is Diff Patch Generator?
Diff Patch Generator is a free online tool for creating and applying unified diff patches. In Generate mode, paste an original and modified version of a file and click Generate — the tool produces a standard unified diff (.patch) file with correct hunk headers, context lines, and --- a/ / +++ b/ file headers compatible with git apply and the POSIX patch command. In Apply mode, paste the original file and a unified diff patch to reconstruct the modified file. All processing runs in your browser — no file content is uploaded.
How to Use Diff Patch Generator
- Generate a patch: Select the Generate Patch tab. Paste original content in the left editor and modified content in the right editor. Set the filename (used in patch headers), then click Generate Patch. The unified diff output appears below with syntax highlighting.
- Apply a patch: Select the Apply Patch tab. Paste the original file content on the left, and the
.patchcontent on the right, then click Apply Patch. The patched result appears in the output area. - Use Load Sample to pre-fill with an example JavaScript function refactor.
- Click Copy to copy the patch or result to clipboard.
Features
- Unified diff generation — standard format compatible with git apply and POSIX patch
- Syntax-highlighted patch output — additions in green, removals in red, hunk headers in blue
- Patch apply — apply any unified diff patch to reconstruct the modified file
- Custom filename — set the filename used in patch
---/+++headers - Clear error messages — shows which line failed to apply and why
- Privacy-first — all processing is local, nothing is uploaded
FAQ
What is unified diff format?
Unified diff is the standard patch format used by git diff and the POSIX diff command. It shows context lines, removals (prefixed with -), and additions (prefixed with +) in hunks marked by @@ line headers. This format is widely supported by patch tools and code review systems.
How do I apply a patch file?
Switch to the "Apply Patch" tab. Paste the original (unmodified) file content on the left, and the .patch content on the right, then click "Apply Patch". The resulting patched file appears in the output area.
Can I use patches generated by git diff?
Yes. Patches generated by git diff --unified or standard POSIX diff -u follow the same unified diff format and can be applied using this tool.
What does "patch does not apply cleanly" mean?
This error means the original file content does not match what the patch expects. This happens when the patch was generated against a different version of the file, or when the context lines in the patch do not match the current file.