{
  "id": 5220094,
  "title": "git commit -m with a path argument doesn't commit what you staged",
  "url": "https://urgent.news/2026/09/03/git-commit-m-with-a-path-argument-doesnt-commit-what-you-staged",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-03T01:37:22.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mahirhir/git-commit-m-with-a-path-argument-doesnt-commit-what-you-staged-4lbd"
  },
  "original_language": "en",
  "account": "When using the command `git commit -m \"msg\" -- path/to/file.rs`, it does not commit the files that you have staged. Instead, it commits only the current working-tree content of the specified file, disregarding the staged changes. This behavior can be dangerous because it commits whatever is on disk at the time of the commit, which may include uncommitted changes from a different session. The index still affects other files in the repository, but for the paths named in the pathspec, git uses the current state of those files on disk. Running `git add --cached` beforehand does not resolve this issue, as the pathspec form of the commit command overrides the staged content. This problem is more noticeable in shared work environments, where multiple users may be editing the same files simultaneously. To avoid this issue, it is recommended to stage exactly what you intend to commit before running the commit command. Running `git diff -- path/to/file.rs` after committing can help verify that the changes committed are indeed your own.",
  "summary": "git commit -m \"msg\" -- doesn't commit what you staged I'd staged a handful of files, run a narrow git commit -m \"fix: ...\" -- path/to/file.rs , and assumed the diff that landed matched what I'd git add ed. It didn't. It matched whatever was sitting on disk in that file at the moment the commit ran, which happened to include a few uncommitted lines from a different working session sharing the same…",
  "key_points": [
    "git commit -m with path argument commits only current working-tree content",
    "Overrides staged changes, disregarding files added with git add --cached",
    "Verifying committed changes with git diff recommended in shared environments"
  ],
  "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."
}