Back to browse
Git-hunk – Stage hunks by hash, no "-p" required

Git-hunk – Stage hunks by hash, no "-p" required

by shhac·Mar 3, 2026·3 points·0 comments

AI Analysis

●●●BangerWizardryBig BrainSolve My Problem

Stable hunk hashing solves real LLM/CI automation gap—git add -p is genuinely unusable for agents.

Strengths
  • Stable SHA-1 hashing keyed to immutable line numbers means multi-step scripted workflows don't break when hunks are staged
  • Fills genuine pain point: `git add -p` interactive-only design blocks automation, agents, CI—no existing tool addresses this
  • Machine-readable `--porcelain` output and deterministic hunk ordering enable reliable agent decision-making without prompt-driving
Weaknesses
  • Niche audience limited to automation-heavy teams and AI agents; adoption depends on LLM framework integration
  • Documentation focuses heavily on agent use cases; less clear value for individual developers already satisfied with `git add -p`
Target Audience

DevOps engineers, LLM agent builders, CI/CD pipeline authors who need deterministic Git workflows

Post Description

git 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.

Similar Projects