From git-surgeon
Performs non-interactive hunk-level git operations: stage/unstage/discard/undo hunks by ID or line range, fold/amend/squash/split/reorder commits. Use for precise control without prompts.
How this skill is triggered — by the user, by Claude, or both
Slash command
/git-surgeon:git-surgeonThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
CLI for hunk-level git operations without interactive prompts. Useful for AI
CLI for hunk-level git operations without interactive prompts. Useful for AI agents that need precise control over which changes to stage, unstage, discard, or undo.
# List unstaged hunks (shows ID, file, +/- counts, preview)
git-surgeon hunks
# List staged hunks
git-surgeon hunks --staged
# Filter to one file
git-surgeon hunks --file=src/main.rs
# List hunks from a specific commit
git-surgeon hunks --commit <HEAD/sha>
# Show all hunks with line numbers (for small commits needing line-range splits)
git-surgeon hunks --commit <sha> --full
# Show blame info (which commit introduced each line)
git-surgeon hunks --blame
git-surgeon hunks --blame --staged
git-surgeon hunks --blame --commit <sha>
# Show full diff for a hunk (lines are numbered for use with --lines)
git-surgeon show <id>
git-surgeon show <id> --commit HEAD
# Stage specific hunks
git-surgeon stage <id1> <id2> ...
# Stage only part of a hunk by line range
git-surgeon stage <id> --lines 5-30
# Stage and commit hunks in one step
git-surgeon commit <id1> <id2> ... -m "message"
# With inline line ranges
git-surgeon commit <id>:1-11 <id2> -m "message"
# Commit hunks directly to another branch (no checkout needed)
git-surgeon commit-to <branch> <id1> <id2> ... -m "message"
git-surgeon commit-to main <id>:1-11 <id2> -m "message"
# Unstage specific hunks
git-surgeon unstage <id1> <id2> ...
git-surgeon unstage <id> --lines 5-30
# Discard working tree changes for specific hunks
git-surgeon discard <id1> <id2> ...
git-surgeon discard <id> --lines 5-30
# Fold existing commits into an earlier commit (default: HEAD into target)
git-surgeon fold <target>
git-surgeon fold <target> --from <commit>
git-surgeon fold <target> --from <commit1> <commit2> <commit3>
# Fold staged changes into an earlier commit
git-surgeon amend <commit>
# Change commit message
git-surgeon reword HEAD -m "new message"
git-surgeon reword <commit> -m "new message"
git-surgeon reword HEAD -m "subject" -m "body"
# Squash ALL commits from <commit> through HEAD into one
git-surgeon squash HEAD~1 -m "combined feature"
git-surgeon squash HEAD~2 -m "Add user auth" -m "Implements JWT-based authentication."
git-surgeon squash <commit> -m "feature complete"
git-surgeon squash HEAD~3 --force -m "squash with merges"
git-surgeon squash HEAD~1 --no-preserve-author -m "use current author"
# Undo specific hunks from a commit (reverse-apply to working tree)
git-surgeon undo <id1> <id2> ... --from <commit>
git-surgeon undo <id> --from <commit> --lines 2-10
# Undo all changes to specific files from a commit
git-surgeon undo-file <file1> <file2> ... --from <commit>
# Split a commit into multiple commits by hunk selection
git-surgeon split HEAD \
--pick <id1> <id2> -m "first commit" \
--rest-message "remaining changes"
# Split with subject + body (multiple -m flags, like git commit)
git-surgeon split HEAD \
--pick <id1> -m "Add feature" -m "Detailed description here." \
--rest-message "Other changes" --rest-message "Body for rest."
# Split with line ranges (comma syntax or repeat ID for non-contiguous ranges)
git-surgeon split <commit> \
--pick <id>:1-11,20-30 <id2> -m "partial split"
# Move a commit after another commit
git-surgeon move <sha> --after <target-sha>
# Move a commit before another commit
git-surgeon move <sha> --before <target-sha>
# Move a commit to the end of the branch
git-surgeon move <sha> --to-end
# Update git-surgeon to the latest version
git-surgeon update
# Split into three+ commits
git-surgeon split HEAD \
--pick <id1> -m "first" \
--pick <id2> -m "second" \
--rest-message "rest"
git-surgeon hunks to list hunks with their IDsgit-surgeon show <id> to inspect a hunk (lines are numbered)git-surgeon commit <id1> <id2> -m "message"git-surgeon stage <id1> <id2>, then git commitgit-surgeon commit <id>:5-30 -m "message"Use commit-to when working in a worktree and you need to commit changes to a
branch checked out elsewhere (e.g., main):
git-surgeon hunks to list hunksgit-surgeon commit-to main <id1> <id2> -m "message"| You have... | Use |
|---|---|
| Staged changes | git-surgeon amend <target> |
| One existing commit, defaulting to HEAD | git-surgeon fold <target> |
| One or more named commits | git-surgeon fold <target> --from <sha> |
fold folds one or more existing commits into an earlier one. The source(s)
(default: HEAD) are removed from history and their changes merge into the
target. Intermediate commits stay untouched. Dirty working tree is autostashed.
Refuses to run when the index already has staged changes.
git-surgeon fold <target> -- fold HEAD into target (most common)git-surgeon fold <target> --from <commit> -- fold a specific non-HEAD commitgit-surgeon fold <target> --from <c1> <c2> <c3> -- fold multiple commits in one passUse --blame to see which commit introduced the surrounding lines:
git-surgeon hunks --blame
Output shows commit hashes for each line:
a1b2c3d src/auth.rs (+2 -0)
8922b52 fn login(user: &str) {
8922b52 validate(user);
0000000 + log_attempt(user); # new line, not yet committed
0000000 + audit(user); # new line, not yet committed
8922b52 }
The context lines show 8922b52 -- that's the commit where this function was
added. If your new lines belong with that change:
git-surgeon commit a1b2c3d -m "add login logging"
git-surgeon fold 8922b52
amend folds staged changes into an earlier commit. For HEAD, amends directly;
for older commits, uses autosquash rebase. Unstaged changes are preserved. For
folding an existing commit instead, use fold.
git-surgeon stage <id1> <id2>git-surgeon amend <commit-sha>Squash collapses ALL commits from the target through HEAD into one, including
any unrelated commits in that range. Preview with git log <target>..HEAD --oneline first. If the range is mixed, use fold --from <c1> <c2> ... to
fold only named commits, or move --to-end the unrelated ones first.
git-surgeon squash HEAD~2 -m "combined"-m flags for subject + body: git-surgeon squash HEAD~1 -m "Subject" -m "Body paragraph"--force to squash ranges containing merge commits--no-preserve-author for current usergit-surgeon hunks --commit <sha> to list hunks in a commitgit-surgeon undo <id> --from <sha>git-surgeon undo-file src/main.rs --from <sha>git-surgeon hunks --commit <sha>
--full to see all lines with line numbers in one callgit-surgeon split <sha> --pick <id1> -m "first" --rest-message "second"-m flags for subject + body: --pick <id> -m "Subject" -m "Body paragraph"id:range syntax for partial hunks: --pick <id>:5-20
--pick <id>:2-6,34-37move reorders commits in history. Useful for grouping related changes or
moving a commit to a logical position after splitting.
git-surgeon move <sha> --after <target> -- place commit right after targetgit-surgeon move <sha> --before <target> -- place commit right before targetgit-surgeon move <sha> --to-end -- place commit at HEAD-2, -3 suffixeshunks to get fresh IDsnpx claudepluginhub raine/git-surgeon --plugin git-surgeonOrganizes git workspace changes into clean, atomic commits following conventional formats. Activates after features, refactors, or explicit commit requests.
Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.