Say you’re halfway through staging a bigger change and spot a typo in another file. I’d want that fix in its own commit right now, without unstaging everything first.
git commit -m "Fix typo in readme" README.md
When you give git commit one or more paths, it commits the current content of those files from your working tree and nothing else. Whatever else you had staged stays staged for the next commit. The docs call this the --only mode, and it’s the default as soon as you list paths.
$ git status -s
M src/export.py
M README.md
$ git commit -m "Fix typo in readme" README.md
$ git status -s
M src/export.py
Note that the whole file goes in, including edits you hadn’t staged. If README.md had two unrelated changes, both end up in the commit. For part of a file, stage the hunk with git add -p first and commit without a path.
It only works for files git already tracks. A new file gives error: pathspec did not match any file(s) known to git until you git add it. And if you want the opposite, staged changes plus that file, there’s --include (-i).
Further reading: git-commit documentation