From tal
This skill should be used when the user asks to "stage specific lines", "partial commit", "stage one hunk", "commit part of a file", "split changes into multiple commits", "stage only some changes", "create atomic commits from mixed changes", or needs to commit a subset of the changes in a file without staging the whole file. Uses `git apply --cached` with a user-supplied unified diff patch to stage exact lines or hunks.
How this skill is triggered — by the user, by Claude, or both
Slash command
/tal:partial-commitThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Stage and commit specific lines or hunks from a file without staging the entire file. Useful for creating atomic, focused commits when a file contains multiple unrelated changes.
Stage and commit specific lines or hunks from a file without staging the entire file. Useful for creating atomic, focused commits when a file contains multiple unrelated changes.
Use git's patch mechanism to stage specific lines:
git apply --cachedInvoke the included helper script to stage specific lines from a file:
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh <file> <patch>
Parameters:
file: Path to the file (relative or absolute)patch: A unified diff patch string containing the changes to stageThe script:
View the changes in a file with context:
git diff --unified=<N> <file>
Where <N> is the number of context lines (default is 3; use larger numbers for more context)
Construct a patch for the lines to stage: A patch follows the unified diff format:
diff --git a/foo.txt b/foo.txt
index abcdef..123456 100644
--- a/foo.txt
+++ b/foo.txt
@@ -10,0 +11,1 @@
+this is the line to stage
Stage the specific lines:
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh foo.txt "$(cat <<'EOF'
diff --git a/foo.txt b/foo.txt
index abcdef..123456 100644
--- a/foo.txt
+++ b/foo.txt
@@ -10,0 +11,1 @@
+this is the line to stage
EOF
)"
Commit the staged changes:
git commit -m "Your commit message"
A unified diff patch consists of:
Header:
diff --git a/file.txt b/file.txt
index <old-hash>..<new-hash> <mode>
--- a/file.txt
+++ b/file.txt
Hunks: Each hunk starts with a hunk header and contains the changes:
@@ -<old-start>,<old-count> +<new-start>,<new-count> @@
context line
-removed line
+added line
context line
- are removed+ are added (space) are context lines@@ specifies line numbersGet the full diff first:
git diff --unified=5 file.txt
Extract the desired hunks:
@@ ... @@) to stageKeep proper patch format:
File has multiple changes, but only one should be staged:
# View the changes
git diff file.txt
# Stage just the line you want
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh file.txt "$(cat <<'EOF'
diff --git a/file.txt b/file.txt
index abc123..def456 100644
--- a/file.txt
+++ b/file.txt
@@ -5,0 +6,1 @@
+new feature line
EOF
)"
# Commit
git commit -m "Add new feature"
File has changes in multiple places, stage only one section:
# Get diff with context
git diff --unified=3 file.txt
# Stage only the first hunk
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh file.txt "<patch-with-one-hunk>"
# Commit
git commit -m "Fix bug in section A"
# Later, stage and commit the other changes separately
File contains both a bug fix and refactoring:
# Stage the bug fix lines
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh file.txt "<bug-fix-patch>"
git commit -m "fix: Correct null pointer handling"
# Stage the refactoring lines
${CLAUDE_PLUGIN_ROOT}/skills/git/partial-commit/stage-lines.sh file.txt "<refactor-patch>"
git commit -m "refactor: Simplify logic"
This skill works well with:
git-branches skill for determining the base branchThe script will fail if:
When the script fails:
--cached flag)git diff --cached to see what's currently stagedgit reset HEAD <file> to unstage if needednpx claudepluginhub tal/plugin-marketplace --plugin talCreates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.