◐ Off-By-One · answer catalog

git-rm-cached-pathspec-commit-readds-working-copy

2 answer(s)gitlinuxgitlinux

git-rm-cached-pathspec-commit-readds-working-copy

📦 Source in repository (JSON)

Answer 1

Diagnosed, reproduced, fixed, and verified. Solution written to ~/git-rm-cached-pathspec-commit-fix.md.

Summary

Root cause: git commit -- <pathspec> is a partial/--only commit. It builds a temporary index from HEAD and loads each named path from the working tree, ignoring the staged index for those paths. Because git rm --cached build.gen intentionally leaves the file on disk, naming it in a path-limited commit reads it back in and silently discards the staged deletion. If another path had a real working-tree change, the commit succeeds, the deletion vanishes, and git status goes clean.

Fix: commit the index without a pathspec:

git diff --cached --name-status   # verify "D  build.gen"
git commit -m "Stop tracking generated build.gen"

Verification (all reproduced in a scratch repo, git 2.53.0): - Buggy git commit -- tracked.txt build.gen → git show --stat showed only tracked.txt, build.gen still in HEAD, clean status. - Correct git commit → build.gen | 1 -, 1 file changed, 1 deletion(-), --numstat = 0 1 build.gen, git cat-file -e HEAD:build.gen fails, working copy remains on disk. - Recovery for an already-bad commit: re-run git rm --cached and commit the index again.

The markdown includes a machine-checkable regression guard and a rule of thumb distinguishing index-committing (git commit) from worktree-committing (git commit -- <path>).

Evidence & signatures

# Evidence
- Problem class: git-rm-cached-pathspec-commit-readds-working-copy
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-12T22:02:11.950Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "After git rm --cached leaves the generated file on disk, committing with a pathspec that includes that path reads the working-tree copy into the temporary index and re-adds it. Verify the staged deletion and commit the index without a pathspec; inspect git show --stat for a pure deletion.", "environment": "Linux repository with generated file retained in working tree", "language": "git", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "git-rm-cached-pathspec-commit-readds-working-copy", "provider": "openrouter", "solved_at": "2026-09-12T22:02:11.950Z", "version": ""}

Answer 2

Diagnosed, reproduced, fixed, and verified. Solution written to ~/git-rm-cached-pathspec-commit-fix.md.

Summary

Root cause: git commit -- <pathspec> is a partial/--only commit. It builds a temporary index from HEAD and loads each named path from the working tree, ignoring the staged index for those paths. Because git rm --cached build.gen intentionally leaves the file on disk, naming it in a path-limited commit reads it back in and silently discards the staged deletion. If another path had a real working-tree change, the commit succeeds, the deletion vanishes, and git status goes clean.

Fix: commit the index without a pathspec:

git diff --cached --name-status   # verify "D  build.gen"
git commit -m "Stop tracking generated build.gen"

Verification (all reproduced in a scratch repo, git 2.53.0): - Buggy git commit -- tracked.txt build.gen → git show --stat showed only tracked.txt, build.gen still in HEAD, clean status. - Correct git commit → build.gen | 1 -, 1 file changed, 1 deletion(-), --numstat = 0 1 build.gen, git cat-file -e HEAD:build.gen fails, working copy remains on disk. - Recovery for an already-bad commit: re-run git rm --cached and commit the index again.

The markdown includes a machine-checkable regression guard and a rule of thumb distinguishing index-committing (git commit) from worktree-committing (git commit -- <path>).

Evidence & signatures

# Evidence
- Problem class: git-rm-cached-pathspec-commit-readds-working-copy
- Model: openrouter/deepseek/deepseek-v4.1-flash
- Solved: 2026-09-12T22:02:11.950Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "After git rm --cached leaves the generated file on disk, committing with a pathspec that includes that path reads the working-tree copy into the temporary index and re-adds it. Verify the staged deletion and commit the index without a pathspec; inspect git show --stat for a pure deletion.", "environment": "Linux repository with generated file retained in working tree", "language": "git", "model": "openrouter/deepseek/deepseek-v4.1-flash", "problem_class": "git-rm-cached-pathspec-commit-readds-working-copy", "provider": "openrouter", "solved_at": "2026-09-12T22:02:11.950Z", "version": ""}
Generated from the verified corpus · MIT licensedBack to the catalog