git-surgeon

Stage, unstage, and discard git hunks non-interactively using stable IDs.

8|Updated Jan 24, 2026
One-click install
npx skills add https://github.com/jfmyers9/agent --skill git-surgeon-jfmyers9
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-surgeon
Source: https://github.com/jfmyers9/agent/tree/main/skills/git-surgeon
Command: npx skills add https://github.com/jfmyers9/agent --skill git-surgeon-jfmyers9

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Non-interactive hunk-level staging, unstaging, and discarding using standard git commands and shasum for hunk identification.

Core Features & Use Cases

  • List Hunks: parse git diff output to generate a short, stable ID per hunk along with file path and a preview.
  • Show Hunk: display the full hunk content for a given ID.
  • Stage / Unstage Hunk(s): apply or reverse-apply selected hunks to the index.
  • Discard Hunk(s): revert targeted hunks in the working tree (destructive).
  • Safety & Workflow: re-list IDs to confirm targets before performing operations.

Quick Start

Ask it to list hunks, then stage or discard a selected hunk.

Frequently Asked Questions about git-surgeon

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I stage individual git hunks non-interactively from the command line?

You can stage individual git hunks non-interactively by listing them via @@ headers to generate stable short IDs, then explicitly applying the selected ID to the git index. This enforces safety by requiring a list-and-apply confirmation step before staging.

What's the best way to discard specific git hunks without reverting the entire file?

Discarding specific git hunks without reverting the entire file requires parsing the diff output to identify target hunks by their stable short IDs, then executing a targeted revert operation. This destructive action requires an explicit list-and-confirm workflow to prevent accidental data loss.

Can I unstage individual hunks from a staged git diff without resetting the whole file?

Yes, unstaging individual hunks from a staged git diff works by reverse-applying the selected hunk ID to the index. The tool resolves patch collisions and uses shasum to ensure the targeted hunk is accurately removed from staging without resetting the entire file.

How does non-interactive hunk staging identify and resolve collisions across multiple files?

Non-interactive hunk staging identifies hunks by parsing @@ headers from git diff output and generating stable short IDs using shasum. It resolves collisions automatically, ensuring accurate patch control across single files and multiple hunks in both staged and unstaged states.

Do I need interactive mode to preview and apply targeted git patches across multiple files?

No, you do not need interactive mode to preview and apply targeted git patches. You can request a hunk list to display the full content and preview for a given ID, then apply or discard it on demand across multiple files using standard git commands.

Why should I use explicit list-and-apply steps before discarding git hunks?

Explicit list-and-apply steps are required before discarding git hunks to enforce operational safety. Re-listing the short IDs confirms the exact targets before any destructive patch reversal occurs, preventing accidental loss of unstaged working tree changes.