{
  "id": 5803875,
  "title": "git commit with a pathspec ignored my index and committed the file as it sat on disk",
  "url": "https://urgent.news/2026/09/05/git-commit-with-a-pathspec-ignored-my-index-and-committed-the-file-as",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-05T17:23:59.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mahirhir/git-commit-with-a-pathspec-ignored-my-index-and-committed-the-file-as-it-sat-on-disk-262g"
  },
  "original_language": "en",
  "account": "When using a git commit command with a pathspec, the staged version of the file is ignored, and the file is committed as it currently exists on disk. This behavior is documented and not a bug. By naming paths in a git commit, the index is bypassed for those paths, and the file is committed as it is on the disk. This issue was observed in a repository where two commits were made within a day of each other, both with named paths but different outcomes. The problem occurs when multiple writers are working in the same tree, and a commit with named paths is made, potentially capturing incomplete or unintended changes. To avoid this issue, it is recommended to stage changes deliberately, commit without a pathspec to ensure only the intended changes are included, and limit the number of writers in a single tree. Testing against different git versions and GUIs is also suggested to fully understand the behavior.",
  "summary": "Run this in an empty directory. It takes about fifteen seconds and it is the whole article. $ git init -q . && git config user.email t@t && git config user.name t $ printf 'v1\\n' > a.txt && git add . && git commit -qm base $ printf 'v2-staged\\n' > a.txt && git add a.txt # stage a version $ printf 'v3-worktree-only\\n' > a.txt # then keep typing $ git show :a.txt v2-staged $ cat a.txt…",
  "key_points": [],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}