添加后忽略 Git 存储库中的目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6618612/
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
Ignoring a directory from a Git repo after it's been added
提问by WinWin
I've learned how to exclude an entire directory in git(add a line bin/
to .gitignore
). And I've learned how to ignore files "after the fact"(i.e. after they have been added to git):
我已经学会了如何排除git的整个目录(添加一行bin/
到.gitignore
)。我已经学会了如何“事后”(即在将文件添加到 git 之后)忽略文件:
git rm --cached <filename>
How do I ignore an entire directory(e.g. bin/
) afterit has been added to a Git repo?
将整个目录(例如bin/
)添加到 Git 存储库后,如何忽略它?
I tried git rm --cached bin/
but all I received was the error:
我试过了,git rm --cached bin/
但我收到的只是错误:
fatal: pathspec 'bin/' did not match any files
致命:路径规范“bin/”不匹配任何文件
When I tried (at the root directory, where .git exists) git rm --cached MyProj/bin/
the error is different:
当我尝试(在 .git 存在的根目录中)时git rm --cached MyProj/bin/
,错误是不同的:
fatal: not removing 'MyProj/bin/' recursively without -r
致命:在没有 -r 的情况下不递归删除“MyProj/bin/”
What does this mean and will I need to commit and/or branch this now?
这是什么意思,我现在需要提交和/或分支吗?
回答by Nic
I was able to get this working with git rm -r --cached bin/
(note the recursive -r
)in the root of the repo - are you talking about findingthe bin directories and untracking them?
我能够在回购的根目录中使用git rm -r --cached bin/
(注意递归-r
) - 您是在谈论查找bin 目录并取消跟踪它们吗?
You will have to commit
before the exclusion is reflected.
commit
在反映排除之前,您必须这样做。
I just saw that you were on Windows. This was in Terminal on OSX, just a heads up.
我刚刚看到你在 Windows 上。这是在 OSX 上的终端中,只是提醒一下。