HN 표시: Git-surgeon – AI 에이전트용 Git add -p
hackernews
|
|
📦 오픈소스
#ai 에이전트
#claude
#git
#git-surgeon
#hunk
#코드 리뷰
원문 출처: hackernews · Genesis Park에서 요약 및 분석
요약
'git-surgeon'는 AI 에이전트가 대형 언어 모델(LLM)의 비대화형 환경에서도 'git add -p'와 같은 세밀한 변경 사항 관리를 수행할 수 있도록 돕는 오픈 소스 도구입니다. 기존 AI가 복잡한 변경을 처리할 때 변경 사항을 파괴하는 우회 방식을 사용하던 문제를 해결하여, 사용자는 파일 전체가 아닌 특정 줄 단위나 헝크(hunk) 단위로 커밋을 생성, 수정, 분리 및 병합할 수 있습니다. 또한, 이 도구는 커밋 내역을 정밀하게 재구성하거나 이전 커밋을 수정하는 등의 고급 기능을 제공하여 AI 코딩 에이전트의 작업 효율성과 안전성을 크게 높여줍니다.
본문
Install · Commands · Examples · Changelog git-surgeon gives AI agents surgical control over git changes without interactive prompts. Stage, unstage, or discard individual hunks. Commit hunks directly with line-range precision. Restructure history by splitting commits or folding fixes into earlier ones. Check out jj-hunk-tool if you're using Jujutsu. AI agents can't use interactive git commands like git add -p . When asked to commit changes separately, they resort to destructive workarounds: ❯ commit the changes separately ⏺ Bash(git diff internal/bot/listing_handler.go) ⎿ diff --git i/internal/bot/listing_handler.go ... ... +83 lines ⏺ Let me reset and make the changes in two separate commits. ⏺ Bash(git checkout internal/bot/listing_handler.go) ← about to destroy changes ⎿ Interrupted With git-surgeon, the agent can inspect hunks and commit them selectively: ❯ commit the changes separately ⏺ I'll commit these as separate changes using git-surgeon. ⏺ Skill(git-surgeon) ⎿ Successfully loaded skill ⏺ Bash(git-surgeon hunks) ⎿ ac34353 internal/bot/listing_handler.go (+6 -3) 15baf94 internal/bot/listing_handler.go (+10 -2) ... ⏺ Bash(git-surgeon commit ac34353 15baf94 7c6ef9e -m "allow edit commands during attribute input") ⏺ Bash(git-surgeon commit 4eefac8 bbba931 -m "add logging for attribute prompts") Highlights - Stage specific lines from a hunk, not just whole hunks (example) - Split commits that mix concerns into focused commits (example) - Retroactively split a combined commit into separate changes (example) # Shell curl -fsSL https://raw.githubusercontent.com/raine/git-surgeon/main/scripts/install.sh | bash # Cargo cargo install git-surgeon # Homebrew brew install raine/git-surgeon/git-surgeon # Claude Code git-surgeon install-skill --claude # OpenCode git-surgeon install-skill --opencode # Codex git-surgeon install-skill --codex Alternatively, for Claude Code via the plugin marketplace: claude plugin marketplace add raine/git-surgeon claude plugin install git-surgeon@git-surgeon Ask Claude Code to make granular commits. It will use git-surgeon automatically to stage individual hunks instead of entire files. | Command | Description | |---|---| hunks | List hunks in the diff | show | Show full diff for a specific hunk | stage | Stage hunks by ID | commit | Stage hunks and commit in one step | commit-to | Commit hunks directly to another branch | unstage | Unstage hunks by ID | discard | Discard working tree changes for hunks | fixup | Fold a commit into an earlier commit | amend | Fold staged changes into an earlier commit | reword | Change the commit message of an existing commit | squash | Squash multiple commits into one | undo | Reverse-apply hunks from a commit | split | Split a commit into multiple commits by hunk selection | move | Move a commit to a different position in history | update | Update git-surgeon to the latest version | Lists all hunks with their IDs, file paths, function context, change counts, and a preview of changed lines. # List unstaged hunks git-surgeon hunks # List staged hunks git-surgeon hunks --staged # Filter to a specific file git-surgeon hunks --file src/main.rs # List hunks from a specific commit git-surgeon hunks --commit HEAD git-surgeon hunks --commit abc1234 # Show full diff with line numbers (useful for small commits) git-surgeon hunks --commit abc1234 --full # Show blame information for each line (which commit introduced it) git-surgeon hunks --blame a1b2c3d src/main.rs fn handle_request (+3 -1) - let result = process(input); + let result = match process(input) { + Ok(v) => v, + Err(e) => return Err(e), + }; e4f5678 src/lib.rs (+1 -0) +use std::collections::HashMap; Each line shows: [function context] (+additions -deletions) Use --blame to see which commit introduced each line: a1b2c3d src/main.rs fn handle_request (+3 -1) 8922b52 context line b538223 -deleted line 0000000 +added line - Context and removed lines show the 7-char hash of the commit that introduced them - Added lines show 0000000 since they're uncommitted - For --commit diffs, added lines show the commit hash instead Shows the full diff (header + all lines) for a single hunk. Each line is prefixed with a 1-based line number for use with --lines . git-surgeon show a1b2c3d # Show a hunk from a specific commit git-surgeon show a1b2c3d --commit HEAD @@ -1,4 +1,6 @@ fn main 1: context 2:-deleted line 3:+added line 4: context Searches both unstaged and staged diffs when no --commit is specified. Stages one or more hunks by ID. Equivalent to selectively answering "y" in git add -p . git-surgeon stage a1b2c3d git-surgeon stage a1b2c3d e4f5678 # Stage only lines 5-30 of a hunk git-surgeon stage a1b2c3d --lines 5-30 Stages hunks and commits them in a single step. Equivalent to running stage followed by git commit . If the commit fails, the hunks are unstaged to restore the original state. Refuses to run if the index already contains staged changes. git-surgeon commit a1b2c3d e4f5678 -m "add pagination" # With
Genesis Park 편집팀이 AI를 활용하여 작성한 분석입니다. 원문은 출처 링크를 통해 확인할 수 있습니다.
공유