Show HN: Git-hunk – Stage hunks by hash, no "-p" required
shhac Tuesday, March 03, 2026git add -p is the only built-in way to stage individual hunks, and it's interactive — you step through hunks one at a time answering "y/n/q/a/d/e/?". That works fine for humans at a keyboard, but it's completely unusable for LLM agents, shell scripts, and CI pipelines.
git-hunk is the non-interactive alternative. It gives every hunk a stable SHA-1 content hash, then lets you stage by hash:
$ git hunk list --oneline
a3f7c21 src/main.zig 42-49 if (flags.verbose) {…
b82e0f4 src/parse.zig 15-28 fn parseArgs(alloc: …
$ git hunk add a3f7c21 staged a3f7c21 → a3f7c21 src/main.zig
The key design choice: hashes are computed from the immutable side's line numbers, so staging one hunk never changes another hunk's hash. This makes multi-step scripted workflows reliable — you can enumerate hunks, make decisions, then stage them without the targets shifting underneath you.Other things it does: line-range selection (a3f7:3-5,8), --porcelain output for machine consumption, count for CI guards, check --exclusive for hash validation, stash individual hunks, and restore to selectively discard changes.
Single static binary, written in Zig, zero runtime dependencies beyond git itself. Install via brew install shhac/tap/git-hunk.
I built this because I was trying to run AI agents in parallel, and stuck to file-level editing they'd fight eachother over what changes they wanted to put into commits. Now I can have multiple agents work in parallel and commit cleanly without needing worktrees.