From git-surgeon
Performs non-interactive hunk-level Git operations: stage, unstage, discard, undo, fixup, amend, squash, split, and reorder commits by ID. Use for precise control without prompts, ideal for AI agents.
npx claudepluginhub raine/git-surgeon --plugin git-surgeonThis skill uses the workspace's default tool permissions.
CLI for hunk-level git operations without interactive prompts. Useful for AI
Analyzes git diff to split changes into logical semantic units, stages hunks sequentially using git-sequential-stage, and commits with Conventional Commits. Activates on mentions of commit, git add, or split changes.
Rewrites feature branch commit history into clean conventional commits telling a progressive story. Handles backup, analysis, and safe recommit for PR cleanup or reorganization.
Guides Git workflow management with atomic commits: organizes staging, branching strategies, merge/rebase, PR management, history cleanup, staged analysis. Use for commits, branches, merges.
Share bugs, ideas, or general feedback.
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 a commit into an earlier commit (default: HEAD into target)
git-surgeon fixup <target>
git-surgeon fixup <target> --from <commit>
git-surgeon fixup <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"fixup folds one or more 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.
git-surgeon fixup <target> -- fold HEAD into target (most common)git-surgeon fixup <target> --from <commit> -- fold a specific non-HEAD commitgit-surgeon fixup <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 fixup 8922b52
amend folds staged changes into an earlier commit. For HEAD, amends directly;
for older commits, uses autosquash rebase. Unstaged changes are preserved.
git-surgeon stage <id1> <id2>git-surgeon amend <commit-sha>Squash collapses ALL commits from the target through HEAD into a single commit.
Every intermediate commit in the range is merged. To fold one commit into a
non-adjacent earlier commit without collapsing the range, use fixup instead.
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 IDs