如何git提交单个文件/目录

dou*_*osh 207 git commit

尝试以下命令:

git commit path/to/my/file.ext -m 'my notes'
Run Code Online (Sandbox Code Playgroud)

在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.
Run Code Online (Sandbox Code Playgroud)

单个文件或目录提交的语法是否不正确?

答: 参数有望在这一顺序...

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

更新:它不再严格:)

Lil*_*ard 340

你的论点是错误的.尝试git commit -m 'my notes' path/to/my/file.ext,或者如果你想更明确,git commit -m 'my notes' -- path/to/my/file.ext.

顺便说一句,git v1.5.2.1是4.5岁.您可能想要更新到更新的版本(1.7.8.3是当前版本).

  • 你做了很好的观察.然而,有趣的是,Windows上的Git 1.7.5.1开始接受`git commit path_to_file -m'message'` (2认同)

wad*_*rld 85

尝试:

git commit -m 'my notes' path/to/my/file.ext 
Run Code Online (Sandbox Code Playgroud)


小智 15

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

git commit -m 'my notes' ./name_of_file.ext
Run Code Online (Sandbox Code Playgroud)


W.P*_*rin 7

使用该-o选项.

git commit -o path/to/myfile -m "the message"
Run Code Online (Sandbox Code Playgroud)

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

  • 那个选项不是必须的。如果您在提交命令中包含文件页面,它只会提交这些文件。 (2认同)

Rah*_* TP 6

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

git commit -m "commit message" path/to/file.extension
Run Code Online (Sandbox Code Playgroud)


小智 5

对于 Windows 7 上的 Git 1.9.5:“我的注释”(双引号)更正了此问题。就我而言,将文件放在 -m“消息”之前或之后没有什么区别;使用单引号是问题所在。