一键导入
git-staging
Stage files, hunks, or specific lines in git non-interactively.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Stage files, hunks, or specific lines in git non-interactively.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Use the Xero MCP server — obtain/refresh OAuth2 bearer tokens, troubleshoot authentication, and pick up other operational notes for working with Xero MCP tools. Use when Xero MCP tools fail with authentication errors, when the bearer token has expired (tokens last ~30 min), before starting any Xero workflow, or for general guidance on Xero MCP usage.
General Xero browser automation notes. Use when automating any Xero page with agent-browser — covers non-standard UI patterns, waiting, and dropdown menus.
Size the agent-browser Chromium window to fill its current screen, leaving a configurable bottom margin for the desktop panel. Use before any agent-browser automation that needs the full screen visible without elements overlapping or scrolling off (e.g. Xero, dense web apps).
Review all unreviewed documents in Hubdoc. Use when reviewing, processing or publishing Hubdoc receipts and bills.
Convert XLSX spreadsheets (single or multi-sheet) to CSV files you can read and grep. Use whenever you need to process an .xlsx report from Xero, Cryptio, bank exports, or any tool that delivers spreadsheet output.
Create Claude Code slash commands, OpenCode command files, and Pi prompt templates that delegate to the right subagent or skill. Use when creating new commands or refactoring existing ones to follow platform conventions.
| name | git-staging |
| description | Stage files, hunks, or specific lines in git non-interactively. |
Use this skill when you need to:
git add -p, git add -i, etc.)Before choosing a staging method, determine what changes exist:
git status # See which files have changes
git diff --no-ext-diff # See all unstaged changes
git diff --cached --no-ext-diff # See already-staged changes
Decision tree:
git add <file>git add for each, or selectively with patch methodgit add -p?Interactive git commands require a TTY and human input. AI agents cannot
reliably fake interactive sessions - attempts using echo "y" or yes are
fragile and often fail. Instead, construct patches programmatically and apply
them directly to the index.
The key insight is that git apply --cached applies a patch directly to the
staging area (index) without modifying the working tree. This lets you stage
precise changes non-interactively.
All temporary patch files should be written to tmp/ within the repository
(not /tmp) to avoid permission prompts. Ensure the directory exists first:
mkdir -p tmp
When you want to stage all changes in a file:
git add <file>
When you need to stage only certain hunks from a file:
Generate the full diff for the file:
git diff <file> > tmp/full.patch
Edit the patch to keep only the hunks you want to stage (use the Edit tool or create a new file with only the desired hunks)
Apply the edited patch to the index:
git apply --cached tmp/selected.patch
When you need to stage only certain lines within a hunk, you must carefully edit the patch to maintain validity:
Generate the diff:
git diff <file> > tmp/full.patch
Edit the patch, following these rules for the hunk you're modifying:
@@ hunk header but adjust the line counts+): remove the entire line from the patch-): change - to a space ( ) to make
it context@@ -X,Y +X,Z @@ header to matchApply:
git apply --cached tmp/selected.patch
A unified diff patch has this structure:
diff --git a/file.txt b/file.txt
index abc123..def456 100644
--- a/file.txt
+++ b/file.txt
@@ -10,6 +10,8 @@ optional context label
context line (unchanged)
-removed line
+added line
context line (unchanged)
@@ -START,COUNT +START,COUNT @@
(space): context line (unchanged, appears in both versions)-: line only in original (will be removed)+: line only in new version (will be added)Given a file with two hunks of changes:
# Generate full diff
git diff --no-ext-diff myfile.py > tmp/full.patch
The patch might look like:
diff --git a/myfile.py b/myfile.py
index abc123..def456 100644
--- a/myfile.py
+++ b/myfile.py
@@ -5,6 +5,7 @@ import os
def foo():
pass
+ # Added comment in first hunk
def bar():
@@ -20,6 +21,7 @@ def bar():
def baz():
pass
+ # Added comment in second hunk
To stage only the second hunk, create a new patch with just that hunk:
diff --git a/myfile.py b/myfile.py
index abc123..def456 100644
--- a/myfile.py
+++ b/myfile.py
@@ -20,6 +21,7 @@ def bar():
def baz():
pass
+ # Added comment in second hunk
Then apply:
git apply --cached tmp/second-hunk.patch
If you have a hunk with multiple additions but only want to stage some:
Original hunk:
@@ -10,4 +10,7 @@
existing line
+line I want to stage
+line I do NOT want to stage
+another line I want to stage
more context
Edit to exclude the unwanted line (remove it entirely and adjust count):
@@ -10,4 +10,6 @@
existing line
+line I want to stage
+another line I want to stage
more context
Note: The +10,7 became +10,6 because we removed one added line.
After applying, verify what was staged:
git diff --cached # Show staged changes
git diff # Show unstaged changes (should include excluded hunks)
git status # Overview of staged/unstaged state
Invalid line counts: If the @@ header counts don't match the actual
lines in the hunk, git apply will fail. Always recount after editing.
Missing newline at EOF: Patches are sensitive to trailing newlines.
Watch for \ No newline at end of file markers.
Whitespace corruption: Ensure context lines start with a space, not an empty prefix. Some editors strip trailing spaces.
Index mismatch: The index abc123..def456 line is optional for
git apply --cached. If you have issues, try removing it.
If git apply --cached fails:
Test the patch first without --cached:
git apply --check tmp/selected.patch
Use verbose mode to see what's happening:
git apply --cached -v tmp/selected.patch
Common error messages:
diff --git or ---/+++ lines