partial-stage-comingled-file-when-add-p-unavailablelisted
Install: claude install-skill hjr15/claude-kit
# Partial-stage a co-mingled file without `git add -p`
## When this fires
You edited a tracked file (often a `MEMORY.md`, changelog, or shared config) and want to commit **only your** hunk — but `git status` shows the same file also carries **another session's uncommitted edits** you must not sweep in. The usual tool, `git add -p`, is interactive and this harness blocks interactive git. `git add <file>` would stage everything, including the foreign edits.
This is the **single-file** case of **the "bare `git commit` sweeps the staged index" trap** (which covers the easier whole-file / explicit-pathspec case).
## The mechanic
Construct the exact content you want committed, hash it into a blob, and point the index at that blob — the working tree (with the foreign edits) is never touched:
```bash
# Build the desired committed content FROM the committed base, applying only your change.
# Example: your change is deleting one line; foreign edits are additions elsewhere.
git show HEAD:path/to/file | grep -v 'my-unique-deletion-token' > /tmp/desired
SHA=$(git hash-object -w /tmp/desired) # write it as a git blob
git update-index --cacheinfo 100644,$SHA,path/to/file # stage THAT blob only
```
Derive `desired` from `HEAD:` (the clean committed base) + your change — **not** from the working-tree file, which already contains the foreign edits. For an addition, append/insert into the `HEAD:` content instead of `grep -v`.
## Verify before committing (mandatory)