如何“git commit”单个文件/目录
我尝试了以下命令:
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.
单个文件或目录提交的语法是否错误?
I tried the following command:
git commit path/to/my/file.ext -m 'my notes'
And received 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 a single file or directory commits?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
你的论点顺序错误。尝试 git commit -m 'mynotes' path/to/my/file.ext,或者如果你想更明确, git commit -m 'mynotes' --path/到/my/file.ext。
顺便说一句,Git v1.5.2.1 已经有 4.5 岁了。您可能想要更新到较新的版本(1.7.8.3 是当前版本)。
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).
尝试:
如果在当前目录,则在路径前面添加
./
;Try:
of if you are in the current directory, add
./
to the front of the path;如果您位于包含该文件的文件夹中
If you are in the folder which contains the file
使用
-o
选项。Use the
-o
option.在输入的提交消息后指定路径,例如:
Specify the path after the entered commit message, like:
对于 Windows 7 上的 Git 1.9.5:“我的注释”(双引号)更正了此问题。就我而言,将文件放在 -m“消息”之前或之后没有什么区别;使用单引号是问题所在。
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.
假设你正在处理一个大项目并打开了多个文件,并且你在单个文件中进行了更改,当你不需要编写
git add .
时,这会将所有文件添加到 git 中,所以您首先需要通过git status
检查您在哪里进行了更改,在这里您将看到文件名旁边的所有路径,复制您进行更改的文件的路径,然后写入git add path
,这里path是文件路径的整行(您修改的文件)。然后你通过 git -m "message" 编写提交消息,然后推送。这将仅推送您与 git add file 一起使用的指定文件
Suppose you are working on big project and have opened multiple files, and you made changes in single file, when you don't need to write
git add .
, this will add all the files to git, so you first need to check where you made changes bygit status
, here you will see all the paths next to the filenames, copy the path of the file where you made change and then writegit add path
, here path is whole line of path to the file (your modified file). Then you write your commit message bygit -m "message"
and then push.This will push only the specified file which you have used with
git add file
如果您在 master 分支中,请尝试:
You try if you are in the master branch: