git rm --cached 和致命的:pathspec
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12564855/
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 rm --cached and fatal: pathspec
提问by Snowcrash
I just tried to checkout my master branch and ran into:
我只是试图结帐我的主分支并遇到了:
error: Untracked working tree file 'app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate' would be overwritten by merge.
So, I tried to delete this file from git (I'd already added an expression in .gitignore to catch it) using:
所以,我尝试从 git 中删除这个文件(我已经在 .gitignore 中添加了一个表达式来捕获它)使用:
git rm --cached app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate
and got:
并得到:
fatal: pathspec 'app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate' did not match any files
So, at a bit of a loss. From my understanding the working file isn't the issue here. However, for completeness, a working file does exist. E.g.
所以,有点亏。根据我的理解,工作文件不是这里的问题。但是,为了完整起见,确实存在工作文件。例如
ls -l app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate
-rw-r--r-- 1 u u 56061 24 Sep 12:42 app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate
采纳答案by Snowcrash
So, the solution is this:
所以,解决方案是这样的:
The file is untracked in this current branch B
该文件在当前分支 B 中未被跟踪
But it exists in the branch we are trying to check out, branch A, so we get a warning that the file in our current working tree will be overwritten (even though we aren't tracking it)
但是它存在于我们试图检出的分支 A 中,因此我们收到警告,指出当前工作树中的文件将被覆盖(即使我们没有跟踪它)
So:
所以:
delete the file in your existing directory (I just moved it somewhere out of the working tree initially to be safe) of branch B
check out the branch you want - i.e. branch A
Remove it from branch A using something like this:
git rm --cached app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate
删除分支 B 的现有目录中的文件(为了安全起见,我只是将它移出工作树的某个位置)
查看您想要的分支 - 即分支 A
使用以下方法将其从分支 A 中删除:
git rm --cached app.xcodeproj/project.xcworkspace/xcuserdata/u.xcuserdatad/UserInterfaceState.xcuserstate
Note: Fwiw, Branch A was my master branch. Branch B was my dev branch.
注意:Fwiw,A 分支是我的主分支。分支 B 是我的开发分支。
回答by Chris Moschini
For the issue in the question title, you can generally solve it this way:
对于题名中的问题,一般可以这样解决:
git rm --cached *
fatal: pathspec 'blah' did not match any files
git ls-files
That will list the files git does have in its index, and you can then remove them explicitly one by one. If for example it lists img/blah.jpg
:
这将列出 git 在其索引中确实包含的文件,然后您可以将它们一一明确删除。例如,如果它列出img/blah.jpg
:
git rm --cached img/blah.jpg
This will solve the pathspec error in the more general case, whether it's a branching issue as it was in the other answer here, or a new .gitignore entry, or a result of using 2 repos in the same dir, etc.
这将解决更一般情况下的 pathspec 错误,无论是分支问题,如此处的另一个答案,还是新的 .gitignore 条目,或在同一目录中使用 2 个 repos 的结果等。
回答by mariovials
simple:
简单的:
git add file.ext
git rm --cached file.ext
or
或者
git add path/*
git rm --cached path/*