Git 提交错误: pathspec‘ commit’与 git 已知的任何文件都不匹配

我想上传一个 Ruby 应用到 Heroku。我从 git init开始,然后输入 git add .,然后使用 git commit -m initial commit

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

Git 提交错误: 路径方面的“提交”与 git 已知的任何文件都不匹配。

有人告诉我,之所以会出现这种情况,是因为争论的顺序错了。

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

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

如果有任何关于如何纠正这个问题的建议,我将不胜感激。

159343 次浏览

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".

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.

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.

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.

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.

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

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

change this

git commit -m 'initial commit'

to

git commit -m "initial commit"

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.

In my case the problem was I had forgotten to add the switch -m before the quoted comment. It may be a common error too, and the error message received is exactly the same

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

Solved! Here is how I solved this issue:

  1. Made an app on Heroku first and prepared all the codes in local_folder to push into it.
  2. Cloned the remote app using heroku git:clone -a app_name
  3. then cd app_name
  4. then copied all the codes into this folder from local_folder
  5. then git add .
  6. then git commit -am "initial commit"
  7. then git push heroku master
  8. Viola!

Type the command git commit -m "Initial Commit" yourself in the terminal/command prompt instead of copy and paste from web page. I believe this will help.