Select Hunks from a Unified Diff

Paste a git diff, inspect the numbered hunks, and export only the hunks you want as a valid smaller patch, split patches, or JSON.

Try:
Selected diff

About this tool

A large patch is easier to review when you can separate the unrelated pieces. Paste a unified diff from git diff, git show, git format-patch, or diff -u; this tool numbers every hunk globally, shows the file and @@ header for each one, then exports only the hunks you select.

Worked example — given this diff:

diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,2 +1,3 @@
 fn main() {
+    println!("hello");
 }
@@ -10,2 +11,2 @@
-old_call();
+new_call();

The default list output is:

1 file · 2 hunks · +2 −1

src/main.rs · 2 hunks · +2 −1
 [1] @@ -1,2 +1,3 @@  +1 −0
 [2] @@ -10,2 +11,2 @@  +1 −1

Set Output to patch and Hunks to 2 to export just the second change with the file headers preserved. Use 1,3-5, 4-, or -2 for ranges, and tick Invert hunk selection to drop the listed hunks instead of keeping them.

Selection filters

Output modes

Limits and edge cases

FAQ

Does this apply the patch to my repository?

No. It only returns text. Copy the patch output to a file or pipe it into your own git apply command after reviewing it.

Why does the default output list hunks instead of returning a patch?

The first step in hunk picking is usually discovery: you need the numbers before you can select them. The list output is the inventory you paste into the hunk selector, similar to running a listing step before filtering a diff.

Can I select individual lines inside one hunk?

No. This version selects whole hunks. Per-line editing requires an interactive editor that can split or rewrite the hunk safely; this one-shot tool deliberately avoids creating hand-edited, possibly inapplicable patches.

What does renumbering do?

If an earlier dropped hunk added two lines, later kept hunks in the same file need their new-side @@ start shifted back by two. With renumbering on, the emitted smaller patch is adjusted for that net delta. Turn it off only when you plan to apply the dropped hunks separately first.

How do file globs work?

Use comma-separated patterns. src/*.rs includes paths matching that pattern, a pattern without a slash also matches a basename, and ! excludes. For example, *, !*.lock keeps every selected hunk except lock-file hunks.

Developer & Automation Access

Run it from the terminal

Same engine as this page, headless — via the gizza CLI:

gizza tool diff-hunk-selector 'diff --git a/src/main.rs b/src/main.rs
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,2 +1,3 @@
 fn main() {
+    println!("hello");
 }'

New to the CLI? Get gizza →

Open it by URL

Pre-fill and auto-run this tool with query parameters — the names match the API/CLI:

https://gizza.ai/tools/diff-hunk-selector/?diff=diff%20--git%20a%2Fsrc%2Fmain.rs%20b%2Fsrc%2Fmain.rs%0A---%20a%2Fsrc%2Fmain.rs%0A%2B%2B%2B%20b%2Fsrc%2Fmain.rs%0A%40%40%20-1%2C2%20%2B1%2C3%20%40%40%0A%20fn%20main%28%29%20%7B%0A%2B%20%20%20%20println%21%28%22hello%22%29%3B%0A%20%7D&output=list&hunks=all%20or%201%2C3-5&invert=true&files=src%2F%2A.rs%2C%20%21%2A.lock&lines=40-120%2C%20200-&renumber=true

Machine-readable descriptor: tool.json — title + parameters JSON Schema for agents.