GIT:错误:pathspec 'xxx 与 git 已知的任何文件都不匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33628862/
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
GIT: error: pathspec 'xxx did not match any file(s) known to git
提问by Xenonite
I have some trouble with a git repository of mine and I cant find the error :(
我的 git 存储库有一些问题,我找不到错误:(
Thing is, I had this repository already in use for a PHP project. everything was fine. Then, I "added" composer to it. I.e., I copied the composer file to the repositorie's root, created a composer.json, and used "composer install". Hence, composer.lock and vendor/ were created for me.
问题是,我已经将这个存储库用于 PHP 项目。一切都很好。然后,我“添加”了作曲家。即,我将 composer 文件复制到存储库的根目录,创建了一个 composer.json,并使用了“composer install”。因此,composer.lock 和 vendor/ 是为我创建的。
Since I didnt want those to be included in the repo, I added the following to the .gitignore
由于我不想将它们包含在 repo 中,因此我将以下内容添加到 .gitignore
composer
composer.lock
vendor/
Now, whenever I use "git add" oder "git commit" from the root, I will get the following errors:
现在,每当我从根使用“git add”或“git commit”时,我都会收到以下错误:
$ git commit * -m "fixed issue #123"
error: pathspec 'composer' did not match any file(s) known to git.
error: pathspec 'composer.lock' did not match any file(s) known to git.
error: pathspec 'vendor' did not match any file(s) known to git.
Obviously, the commit (or add) does not work so I have to manually specify files to add or commit. Bummer.
显然,提交(或添加)不起作用,因此我必须手动指定要添加或提交的文件。无赖。
I cannot find the problem :( Anyone knows how to fix this?
我找不到问题:(有人知道如何解决这个问题吗?
BTW I am using git version 2.4.9 (Apple Git-60)
顺便说一句,我使用的是 git 2.4.9 版(Apple Git-60)
采纳答案by Xenonite
Well, years passed, new git versions were released, yet the problem still show up for me from time to time. The posted fixes unfortunately do not help. Yet, instead of committing with git commit . -m "xyz"
doing a
好吧,多年过去了,新的 git 版本发布了,但问题仍然时不时地出现在我面前。不幸的是,发布的修复程序无济于事。然而,与其承诺git commit . -m "xyz"
做一个
git commit -a -m "xyz"
git commit -a -m "xyz"
does wonders.
创造奇迹。
Cheers.
干杯。
回答by swidmann
I often have this problem if something has changed, added files to gitignore or something else. Maybe you have to rebuild the index.
如果某些内容发生更改,将文件添加到 gitignore 或其他内容,我经常会遇到此问题。也许你必须重建索引。
Updated:added recursive and file param to git rm
更新:将递归和文件参数添加到git rm
In my case this worked:
在我的情况下,这有效:
remove cached files(only the paths are removed from the index, not the real files!!!)
删除缓存文件(仅从索引中删除路径,而不是真正的文件!!!)
git rm -r --cached .
add all files to the index
将所有文件添加到索引
git add .
commit
犯罪
git commit -m "hopefully fixed pathspec error"
UPDATE:If this won't work, try the following:
更新:如果这不起作用,请尝试以下操作:
- Get a new checkout from your repo
- remove
composer, composer.lock, vendor/
from your .gitignore - run the above suggestion again
- move the folders
composer, composer.lock, vendor/
outside your repo - add and commit, maybe add with
-A
to add that the files are deleted - add
composer, composer.lock, vendor/
to your .gitignore and commit - move back the folders
composer, composer.lock, vendor/
to your repo
- 从您的回购中获取新的结帐
composer, composer.lock, vendor/
从你的 .gitignore 中删除- 再次运行上述建议
- 将文件夹移到
composer, composer.lock, vendor/
你的仓库之外 - 添加和提交,也许添加
-A
以添加文件被删除 - 添加
composer, composer.lock, vendor/
到您的 .gitignore 并提交 - 将文件夹移回
composer, composer.lock, vendor/
您的仓库
Now it should be gone from the repo and due to your .gitignore, never will be commited again. Hopefully the pathspec error is gone :)
现在它应该从 repo 中消失,并且由于您的 .gitignore,永远不会再次提交。希望 pathspec 错误消失了 :)