Git commit with pathspec bypasses index, commits unsaved disk version instead
A documented Git behaviour causes 'git commit' with a named pathspec to bypass the staging index and commit the working-tree version of a file directly from disk. This means any staged changes are silently discarded, and the committed file reflects whatever state it was in at the moment of the commit — including partially written content. The author discovered this after two real commits captured incomplete file versions, one of which truncated an audit document at 74 of 198 lines. The '-i' flag does not fix the issue, as named paths still pull from disk regardless. The recommended workaround is to stage changes deliberately and run 'git commit' without any pathspec, ensuring only reviewed, indexed content is committed.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in