Don't like ads? Go Ad-Free Today

Git Unified Diff & Patch Generator

DeveloperText
ADVERTISEMENT · REMOVE?
Used in the --- header
Used in the +++ header
Unchanged lines shown around each change
ADVERTISEMENT · REMOVE?

Guide

Git Unified Diff & Patch Generator

Git Unified Diff & Patch Generator

Paste an original snippet and a modified snippet to instantly generate a valid unified diff in .patch format. The output uses correct hunk headers (@@ -L,N +L,N @@) so the patch applies cleanly with git apply or the standard patch utility — no hand-fixing required.

How to Use

  1. Paste the original text into the Original textarea.
  2. Paste the modified version into the Modified textarea.
  3. Optionally adjust the Original Path and Modified Path to set the filenames used in the --- and +++ headers.
  4. Drag the Context Lines slider to choose how many unchanged lines surround each change (0–10).
  5. Copy the unified diff or download it as changes.patch for use with git apply or patch -p1.

Features

  • Standards-compliant unified diff – correct hunk headers, line counts, and context handling.
  • Configurable context – choose 0 to 10 surrounding context lines per hunk.
  • Custom file paths – set the a/ and b/ filenames so the patch targets the right file.
  • Stat summary – instant +N / -N readout of added and removed lines.
  • One-click download – export the patch as changes.patch, ready for git apply.
  • Runs entirely in your browser – nothing is uploaded; works offline once the page is loaded.

When to Use This Tool

Reach for this generator whenever you need to share a code change as a patch — for example, when posting on an issue tracker, mailing a contribution, or pasting AI-suggested edits into a real codebase. It is especially useful for converting LLM “before / after” snippets into a patch you can actually apply with one command.

ADVERTISEMENT · REMOVE?

FAQ

  1. What is a unified diff?

    A unified diff is the standard text format for describing changes between two files. It begins with two header lines (--- old and +++ new) followed by one or more hunks. Each hunk starts with @@ -oldStart,oldCount +newStart,newCount @@ and lists context, removed (-), and added (+) lines. The format was popularized by the GNU diff utility and is the format git apply and patch expect by default.

  2. How does git apply use a unified diff?

    git apply reads a unified diff and replays each hunk against the matching file in the working tree. It uses the hunk's line numbers and surrounding context to locate the change site, then performs the additions and removals. If the context does not match (because the target file has drifted), git apply rejects the patch unless you pass options such as --3way or --reject.

  3. What do the numbers in @@ -1,5 +1,6 @@ mean?

    The hunk header tells you where the change lives and how many lines it spans on each side. -1,5 means the original file segment starts at line 1 and covers 5 lines (the deleted plus context lines). +1,6 means the new file segment starts at line 1 and covers 6 lines (the added plus context lines). When the count is 1, the comma and number are sometimes omitted (for example, @@ -42 +42 @@).

  4. Why do extra context lines matter in a patch?

    Context lines are the unchanged lines printed above and below each change. They give the patch tool an anchor for finding the change in the target file, even if the surrounding code has shifted by a few lines. More context (for example 5 or 7 lines) makes a patch more resilient to small drift but also makes it larger; the GNU diff default of 3 lines is usually a good balance.

Want To enjoy an ad-free experience? Go Ad-Free Today

Install Our Extensions

Add IO tools to your favorite browser for instant access and faster searching

Add to Chrome Extension Add to Edge Extension Add to Firefox Extension Add to Opera Extension

Scoreboard Has Arrived!

Scoreboard is a fun way to keep track of your games, all data is stored in your browser. More features are coming soon!

ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?
ADVERTISEMENT · REMOVE?

News Corner w/ Tech Highlights

Get Involved

Help us continue providing valuable free tools

Buy me a coffee
ADVERTISEMENT · REMOVE?