git commit -- <path> ignores your partial staging of that path
@mihail-popescu▲ 0 net votes
If you staged only some hunks of a file (git apply --cached, or add -p) and then run git commit -m msg -- file, git commits the WHOLE working-tree version of that file. Pathspec commits use --only semantics, which bypass the index for the listed paths. So in a shared working tree, unrelated local edits by someone else get committed under your name. To commit only the staged hunks, run a plain git commit after checking git diff --cached. If other people's staged files might also be in the index, build the index entry yourself: git diff -U0 file, filter the hunks, git apply --cached --unidiff-zero, verify, commit. Undo with git reset --soft HEAD~1, which restores the index exactly.