git commit 错误:pathspec 'commit' 与 git 已知的任何文件都不匹配

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16951207/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:20:20  来源:igfitidea点击:

git commit error: pathspec 'commit' did not match any file(s) known to git

gitcommand-line

提问by user2457644

I am trying to upload a Ruby app to Heroku. I start with git initand then I type git add .and then I use git commit -m initial commit.

我正在尝试将 Ruby 应用程序上传到 Heroku。我开始,git init然后我输入git add .,然后我使用git commit -m initial commit.

Whenever I use git commit -m, I receive an error message saying:

每当我使用 时git commit -m,我都会收到一条错误消息:

git commit error:pathspect 'commit' did not match any file(s) known to git.

git commit 错误:pathspect 'commit' 与 git 已知的任何文件都不匹配。

I have been told that this is happening because the arguments are in the wrong order.

有人告诉我,这是因为参数顺序错误。

The thing I noticed is that when I use git add .it will not list the files that are being added because it will just go to the next line.

我注意到的是,当我使用git add .它时不会列出正在添加的文件,因为它只会转到下一行。

I suspect that I am having this problem because my files are not really being added.

我怀疑我遇到了这个问题,因为我的文件并没有真正被添加。

I would appreciate any advice about how to correct this problem.

我将不胜感激有关如何纠正此问题的任何建议。

回答by kan

The command line arguments are separated by space. If you want provide an argument with a space in it, you should quote it. So use git commit -m "initial commit".

命令行参数用空格分隔。如果你想提供一个带有空格的参数,你应该引用它。所以使用git commit -m "initial commit".

回答by Nicks

I would just like to add--

我只想补充——

In windows the commit message should be in double quotes(git commit -m "initial commit"instead of git commit -m 'initial commit'), as I spent about an hour, just to figure out that single quote is not working in windows.

Windows 中,提交消息应该用双引号git commit -m "initial commit"而不是git commit -m 'initial commit'),因为我花了大约一个小时,只是为了弄清楚单引号在 Windows 中不起作用。

回答by zeeawan

In my case, this error was due to special characters what I was considering double quotes as I copied the command from a web page.

就我而言,此错误是由于特殊字符引起的,我在从网页复制命令时考虑了双引号。

回答by Linux_Google

Had this happen to me when committing from Xcode 6, after I had added a directory of files and subdirectories to the project folder. The problem was that, in the Commit sheet, in the left sidebar, I had checkmarked not only the root directory that I had added, but all of its descendants too. To solve the problem, I checkmarked only the root directory. This also committed all of the descendants, as desired, with no error.

在我将文件目录和子目录添加到项目文件夹之后,从 Xcode 6 提交时是否发生了这种情况。问题是,在提交表的左侧边栏中,我不仅选中了我添加的根目录,还选中了它的所有子目录。为了解决这个问题,我只勾选了根目录。这也根据需要提交了所有后代,没有错误。

回答by Sai Gopi N

I figured out mistake here use double quotations instead of single quotations.

我发现错误在这里使用双引号而不是单引号。

change this

改变这个

git commit -m 'initial commit'

git commit -m 'initial commit'

to

git commit -m "initial commit"

git commit -m "initial commit"

回答by Jerry Krinock

Had this happen to me when committing from Xcode 6, after I had added a directory of files and subdirectories to the project folder. The problem was that, in the Commitsheet, in the left sidebar, I had checkmarked not only the root directory that I had added, but all of its descendants too. To solve the problem, I checkmarked only the root directory. This also committed all of the descendants, as desired, with no error.

在我将文件目录和子目录添加到项目文件夹后,从 Xcode 6 提交时是否发生了这种情况。问题是,在提交表的左侧边栏中,我不仅选中了我添加的根目录,还选中了它的所有子目录。为了解决这个问题,我只勾选了根目录。这也根据需要提交了所有后代,没有错误。

回答by Jerry Krinock

Please take note that in windows, it is very important that the git commit -m "initial commit"has the initial commit texts in double quotes. Single quotes will throw a path spec error.

请注意,在 Windows 中,git commit -m "initial commit"将初始提交文本放在双引号中非常重要。单引号将引发路径规范错误。

回答by T G

In my case, the problem was I used wrong alias for git commit -m. I used gcalias which dit not meant git commit -m

就我而言,问题是我为git commit -m. 我使用了gc不是这个意思的别名git commit -m

回答by u5844373

if there are anybodys using python os to invoke git,u can use os.system('git commit -m " '+str(comment)+'"')

如果有人使用 python os 调用 git,你可以使用 os.system('git commit -m " '+str(comment)+'"')

回答by Haibin Chen

I have encounter the same problem. my syntax has no problem. What I found is that I copied and pasted git commit -m "comments"from my note. I retype it, the command execute without issue. It turns out the -and " "are the problem when I copy paste to terminal.

我遇到了同样的问题。我的语法没有问题。我发现我从笔记中复制并粘贴了git commit -m "comments"。我重新输入它,命令执行没有问题。事实证明-“”是我将粘贴复制到终端时的问题。