我尝试了以下命令:

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

在Git版本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.

这是单个文件或目录提交的错误语法吗?


当前回答

在输入的提交消息后指定路径,例如:

git commit -m "commit message" path/to/file.extension

其他回答

如果您在包含该文件的文件夹中

git commit -m 'my notes' ./name_of_file.ext

对于Windows 7上的Git 1.9.5:“my Notes”(双引号)更正了这个问题。在我的例子中,把文件放在-m 'message'之前或之后没有区别;使用单引号是问题所在。

使用-o选项。

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

-o,——only只提交指定的文件

如果你在主分支中,你试试:

git commit -m "Commit message" -- filename.ext

在输入的提交消息后指定路径,例如:

git commit -m "commit message" path/to/file.extension