如何 git 提交单个文件/目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8795097/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to git commit a single file/directory
提问by doublejosh
Tried the following command:
尝试了以下命令:
git commit path/to/my/file.ext -m 'my notes'
Receive an error in git version 1.5.2.1:
在 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.
Is that incorrect syntax for singe file or directory commits?
单个文件或目录提交的语法不正确吗?
ANSWER:Arguments wereexpected in this order...
答:参数都有望在这一顺序...
git commit -m 'my notes' path/to/my/file.ext
git commit -m 'my notes' path/to/my/file.ext
UPDATE:it's not strict anymore :)
更新:它不再严格了:)
回答by Lily Ballard
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
.
你的论点顺序错误。尝试git commit -m 'my notes' path/to/my/file.ext
,或者如果您想更明确,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).
顺便提一下,git v1.5.2.1 已经有 4.5 年的历史了。您可能想要更新到更新的版本(1.7.8.3 是当前版本)。
回答by wadesworld
Try:
尝试:
git commit -m 'my notes' path/to/my/file.ext
回答by Piethon
If you are in the folder which contains the file
如果您在包含该文件的文件夹中
git commit -m 'my notes' ./name_of_file.ext
回答by W.Perrin
Use the -o
option.
使用该-o
选项。
git commit -o path/to/myfile -m "the message"
-o, --only commit only specified files
-o, --only 只提交指定的文件
回答by Rahul TP
Specify path after entered commit message, like:
输入提交消息后指定路径,例如:
git commit -m "commit message" path/to/file.extention
回答by EddieBaby
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.
对于 Windows 7 上的 git 1.9.5:“我的笔记”(双引号)更正了这个问题。在我的情况下,将文件放在 -m 'message' 之前或之后。没有区别;使用单引号是问题所在。