git 为什么我收到“提交失败并出现错误:pathspec ...没有匹配任何文件”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28189880/
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
Why am I getting "Commit failed with error: pathspec ... did not match any file(s)"?
提问by Dario
I am having some issues with Git.
我在使用 Git 时遇到了一些问题。
I have a repository where I can commit any file to without problem. However, there is a single file 'Funder.php' which, when I try committing, tells me there is an error as:
我有一个存储库,我可以毫无问题地向其中提交任何文件。但是,有一个文件“Funder.php”,当我尝试提交时,它告诉我有一个错误:
Commit failed with error:
pathspec 'application/libraries/Funder.php' did not match any file(s) known to git.
I am quite new to this, so was wondering if anybody could please help?
我对此很陌生,所以想知道是否有人可以帮忙?
采纳答案by jub0bs
This is the error you get when you attempt to run
这是您尝试运行时遇到的错误
git commit <file>
but <file>
hasn't been staged yet; in other words, Git hasn't been told about it, yet. This is most likely what's happening here. Run
但<file>
还没有上演;换句话说,Git 还没有被告知这件事。这很可能是这里发生的事情。跑
git add application/libraries/Funder.php
then try to commit.
然后尝试提交。
回答by Daniel Silva
The reason why this error happens is pointed in this post: https://stackoverflow.com/a/29485441/2769415
发生此错误的原因在这篇文章中指出:https: //stackoverflow.com/a/29485441/2769415
Windows' file system is mostly case-insensitive, so you cannot rename a file by just changing its capitalization. Instead, you will have to use a temporary name in between.
Windows 的文件系统大多不区分大小写,因此您不能仅通过更改大小写来重命名文件。相反,您必须在两者之间使用一个临时名称。
Solution: Rename the file back to the original one, then rename it to a different name, then back to the one with the correct capitalization. Git will not throw the bug anymore.
解决方案:将文件重命名回原始文件名,然后将其重命名为不同的名称,然后返回到大小写正确的文件名。Git 不会再抛出这个错误了。
Example:
例子:
Created FOOBar class.
Renamed it to FooBar and then got the error.
Rename it back to FOOBar.
Rename to FooBarTest.
Rename to FooBar.
Git works now.
回答by Oscar Salguero
I had the same problem in Android Studio after renaming some activities. I tried adding (git add) and moving (git mv) the files but never helped and I was getting the same message again and again.
重命名一些活动后,我在 Android Studio 中遇到了同样的问题。我尝试添加 (git add) 和移动 (git mv) 文件,但从来没有帮助,而且我一次又一次地收到相同的消息。
Finally I decided to backup the classes in the package that had the problematic file in a separate folder in my HDD, then I removed the files from the original folder and in the terminal I did:
最后,我决定将包中包含问题文件的类备份到硬盘的单独文件夹中,然后我从原始文件夹中删除了这些文件,并在终端中执行了以下操作:
rm app/src/main/java/com/path/to/package/with/problematic/files/
Then recreated the deleted package via Android Studio and copied and pasted my classes back there. After that I was able to commit without any issues.
然后通过 Android Studio 重新创建删除的包并将我的类复制并粘贴回那里。在那之后,我能够毫无问题地提交。
回答by Julian Soro
Here's a concise answer on the quickest way to resolve this issue. Similar to @cmbind55 post but to the point.
这是有关解决此问题的最快方法的简明答案。类似于@cmbind55 帖子,但重点突出。
Problem:I have added a file that I later renamed.
问题:我添加了一个后来重命名的文件。
Solution:
解决方案:
- Un-add the old file name
- 取消添加旧文件名
git reset HEAD oldFileName.file
git reset HEAD oldFileName.file
- Now, add the new file name
- 现在,添加新文件名
git add newFileName.file
git add newFileName.file
- Commit and be happy
- 承诺并快乐
回答by cmbind55
I had this failing commit scenario due to a renamed directory.
由于重命名的目录,我遇到了这个失败的提交场景。
This was the originally created directory with a capitalization mistake:
这是最初创建的目录有大写错误:
application/Templates/lists/index.html
Within the IDE, I had agreed to add this file to the existing git repo. In later testing, I discovered I had a case-sensitive path issue with the capitalization of "Templates". Within the IDE, I simply renamed the directory to "templates" (changed to lower-case). I did not record the actual sequence of events around this, but later when my commit failed with the following message, I had a hunch this was this issue. Apparently, the IDE did not fully handle this case of renaming a directory.
在 IDE 中,我同意将此文件添加到现有的 git 存储库中。在后来的测试中,我发现“模板”的大小写存在区分大小写的路径问题。在 IDE 中,我只是将目录重命名为“templates”(改为小写)。我没有记录围绕此的实际事件序列,但后来当我的提交失败并显示以下消息时,我预感到这就是这个问题。显然,IDE 没有完全处理重命名目录的这种情况。
The IDE commit error message:
IDE 提交错误消息:
Commit failed with error: pathspec "application/templates/lists/index.html" did not match any file(s) known to git.
提交失败并出现错误:路径规范“application/templates/lists/index.html”与 git 已知的任何文件都不匹配。
After doing some reading, my strategy was to take the file back out and then add it again. I unstaged the suspect file
在做了一些阅读之后,我的策略是将文件取出,然后再次添加。我取消暂存可疑文件
git reset HEAD lists/Templates/lists/index.html
Note, git status only showed the directory here... Not the file.
请注意, git status 仅显示此处的目录...不是文件。
Untracked files:
(use "git add <file>..." to include in what will be committed)
lists/templates/
Then, I added back with the corrected directory name (I only used the path for the add, following the lead from git status).
然后,我添加了更正的目录名称(我只使用了添加路径,遵循 git status 的引导)。
git add lists/templates/
After this, my commit succeeded. I'm not sure if this was the ideal technique, but it resolved the commit error in my case.
在此之后,我的提交成功了。我不确定这是否是理想的技术,但它解决了我的情况下的提交错误。
回答by Trilochan
i had same problem. just change 'Initial comment single quotes '' to double quotes ""
我有同样的问题。只需将“初始注释单引号”更改为双引号“”
回答by Fredrick Anyera M
if working from terminal ensure that you have a message flag in your command.
如果从终端工作,请确保您的命令中有一个消息标志。
git commit "Your Commit Message" //Throws an error: pathspec '3.
git commit "Your Commit Message" //Throws an error: pathspec '3.
git commit -m "Your Commit Message" //No error thrown
git commit -m "Your Commit Message" //No error thrown
回答by alaboudi
I had a similar problem but fixed it. I should have been using "" instead of '' in windows command line
我有一个类似的问题,但修复了它。我应该在 Windows 命令行中使用 "" 而不是 ''
回答by Evgeniy Mishustin
I had the same problem. None of the answers here did not help me to resolve the issue. After being stuck for two days, I drew attention that the whole filename with path are very long. I did refactoring renaming it to something less complicated and rearranging folders to reduce the full filename length and it worked!
我有同样的问题。这里的所有答案都没有帮助我解决问题。卡了两天后,我提请注意整个文件名和路径很长。我确实重构了将其重命名为不太复杂的内容并重新排列文件夹以减少完整的文件名长度并且它起作用了!
回答by serge-k
iOS 9.2.1, Xcode 7.2.1, ARC enabled
iOS 9.2.1、Xcode 7.2.1、ARC 已启用
Ran into this while changing "contents.json" file for my LaunchImage asset catalog. You may elect to use the terminal commands provided as the answer, but try this simpler way...
在更改 LaunchImage 资产目录的“contents.json”文件时遇到了这个问题。您可以选择使用提供的终端命令作为答案,但请尝试这种更简单的方法......
Source Control -> Refresh Status
源代码管理 -> 刷新状态
Hope this helps. Cheers!
希望这可以帮助。干杯!