在添加 Git 回购目录后,忽略该目录

我已经学会了 如何在 git 中排除整个目录(在 .gitignore上加一行 bin/)。我还学习了 如何“事后”忽略文件(即在它们被添加到 git 之后) :

git rm --cached <filename>

如何忽略已添加到 Git 回购中的整个 目录(例如 bin/) 之后

我尝试了 git rm --cached bin/,但收到的只有错误:

Pathspec‘ bin/’与任何文件都不匹配

当我尝试(在根目录中. git 存在) git rm --cached MyProj/bin/时,错误是不同的:

不删除「 MyProj/bin/」 递归不用-r

这意味着什么? 我现在需要提交和/或分支它吗?

76486 次浏览

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 finding the bin directories and untracking them?

You will have to commit before the exclusion is reflected.

I just saw that you were on Windows. This was in Terminal on OSX, just a heads up.

On windows:

git rm -r --cached ./FOLDERNAME/

And then do the other stuffs. (add and commit and push)

(Note that on windows you should use ./ before the folder name, just like above.)