Git-hunk: the missing half of Git add

mil221 pts1 comments

git-hunk — The missing half of git add

git-hunk<br>The missing half of git add.<br>git add -p is interactive. Your agents can't use it.

Install

View on GitHub

Zig &middot; v0.10.1 &middot; MIT

The problem<br>Partial staging is interactive-only

The only built-in way to stage individual hunks is git add -p — an interactive prompt that blocks automation.

Interactive staging

$ git add -p<br>@@ -42,6 +42,8 @@<br>+ if (flags.verbose) {<br>+ log.info("enabled");<br>+ }

(1/3) Stage this hunk [y,n,q,a,d,e,?]? █

✗ Requires a human at the keyboard<br>✗ Blocks CI/CD pipelines<br>✗ Non-deterministic hunk ordering<br>✗ Unusable by LLM agents

Hash-based staging

$ git hunk list --oneline<br>a3f7c21 src/main.zig 42-49 if (flags.verbose) {…<br>b82e0f4 src/parse.zig 15-28 fn parseArgs(alloc: …<br>c91d3a8 src/args.zig 8-8 const quiet: bool = …

$ git hunk add a3f7c21<br>staged a3f7c21 &rarr; a3f7c21 src/main.zig

✓ Fully non-interactive<br>✓ Stable SHA-1 content hashes<br>✓ Deterministic across runs<br>✓ Machine-readable output

How it works<br>Enumerate. Select. Stage.

Three commands. No prompts. No interaction.

Enumerate<br>$ git hunk list

See every hunk with a stable content hash. Same content always produces the same hash.

Select<br>$ git hunk diff a3f7

Inspect any hunk by its hash prefix. Review the full diff before staging.

Stage<br>$ git hunk add a3f7

Stage by hash — deterministic and scriptable. Remaining hunk hashes stay stable.

The key insight<br>Hashes that don't break

When you stage a hunk, the remaining hashes stay the same. This is what makes scripted multi-step workflows reliable.

Before staging

a3f7c21 src/main.zig 42-49 if (flags.verbose) {…<br>b82e0f4 src/parse.zig 15-28 fn parseArgs(alloc: …<br>c91d3a8 src/args.zig 8-8 const quiet: bool = …

$ git hunk add a3f7c21

After staging

b82e0f4 src/parse.zig 15-28 fn parseArgs(alloc: … &larr; same hash<br>c91d3a8 src/args.zig 8-8 const quiet: bool = … &larr; same hash

How it works

SHA1( file_path + '\0' + stable_line + '\0' + diff_lines )

Hashes use the immutable side's line numbers. Staging one hunk can't shift another hunk's anchor point, so hashes remain stable across operations.

Built for<br>Stage hunks by hash, not by prompt<br>>_<br>LLM Agents

Agents can't drive interactive prompts. git-hunk gives them deterministic hashes to enumerate, select, and stage programmatically.

--porcelain<br>#!/<br>Scripts & CI

Deterministic staging in pipelines. Use count as a guard and check to validate hashes before staging.

--exclusive<br>Humans

No more y/n/q/a/d/e/? guessing. See all hunks at once, inspect any hunk by hash, stage exactly what you want.

--oneline

Commands<br>Everything you need<br>Discover Stage Manage Validate<br>list<br>Enumerate hunks with stable content hashes<br>Compact output<br>git hunk list --oneline

View staged hunks<br>git hunk list --staged

Machine-readable<br>git hunk list --porcelain

diff<br>Inspect a hunk's full diff before staging<br>View by hash prefix<br>git hunk diff a3f7

Specific lines<br>git hunk diff a3f7:3-5

count<br>Count available hunks — bare integer for scripting<br>CI guard<br>git hunk count

add<br>Stage hunks by content hash<br>Stage by hash<br>git hunk add a3f7c21

Stage multiple<br>git hunk add a3f7c21 b82e0f4

Stage specific lines<br>git hunk add a3f7:3-5,8

Stage everything<br>git hunk add --all

reset<br>Unstage hunks from the index<br>Unstage by hash<br>git hunk reset a3f7c21

Unstage all<br>git hunk reset --all

commit<br>Stage hunks and commit in one step<br>Select and commit<br>git hunk commit a3f7 b82e -m "feat: add validation"

stash<br>Create real git stash entries from specific hunks<br>Stash with message<br>git hunk stash a3f7 -m "save auth changes"

restore<br>Discard worktree changes for specific hunks<br>Preview before discarding<br>git hunk restore --dry-run a3f7

Discard a hunk<br>git hunk restore a3f7c21

check<br>Verify hunk hashes still exist — use as CI guards<br>Validate hashes<br>git hunk check a3f7 b82e

Assert exact set<br>git hunk check --exclusive a3f7 b82e

Install<br>Get started<br>Homebrew

brew install shhac/tap/git-hunk

AI Agent Skill

npx skills add shhac/git-hunk

GitHub Release (macOS)

curl -L https://github.com/shhac/git-hunk/releases/latest/download/git-hunk-macos-universal.tar.gz | tar xz

Build from Source

git clone https://github.com/shhac/git-hunk.git && cd git-hunk && zig build -Doptimize=ReleaseFast

Demo<br>See it in action

hunk stage hash hunks hashes staging

Related Articles