Advertisement
Advertisement


How to git commit a single file/directory


Question

Tried the following command:

git commit path/to/my/file.ext -m 'my notes'

Receive an error in git version 1.5.2.1:

error: pathspec '-m' did not match any file(s) known to git.
error: pathspec 'MY MESSAGE' did not match any file(s) known to git.

Is that incorrect syntax for singe file or directory commits?

ANSWER: Arguments were expected in this order...

git commit -m 'my notes' path/to/my/file.ext

UPDATE: it's not strict anymore :)

2018/05/09
1
221
5/9/2018 11:05:41 AM

Accepted Answer

Your arguments are in the wrong order. Try git commit -m 'my notes' path/to/my/file.ext, or if you want to be more explicit, git commit -m 'my notes' -- path/to/my/file.ext.

Incidentally, git v1.5.2.1 is 4.5 years old. You may want to update to a newer version (1.7.8.3 is the current release).

2012/01/09
358
1/9/2012 8:58:43 PM

Try:

git commit -m 'my notes' path/to/my/file.ext 
2012/01/09

If you are in the folder which contains the file

git commit -m 'my notes' ./name_of_file.ext
2016/02/16

Use the -o option.

git commit -o path/to/myfile -m "the message"

-o, --only commit only specified files

2018/03/03

Specify path after entered commit message, like:

git commit -m "commit message" path/to/file.extention
2019/04/08

For git 1.9.5 on Windows 7: "my Notes" (double quotes) corrected this issue. In my case putting the file(s) before or after the -m 'message'. made no difference; using single quotes was the problem.

2016/09/30

Source: https://stackoverflow.com/questions/8795097
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]