命令 `git rm -r --cached /.idea` 出现问题

Trouble with command `git rm -r --cached /.idea`

就我而言,我有一个新项目。在我之前的开发人员提交 git 中的所有文件(包括构建文件夹、.idea 文件夹等)。我创建了 .gitignore,现在我想删除自动通用文件和系统文件。早些时候我分三步做同样的事情: 1)删除存储库中的所有自动通用文件和系统文件;提交并推进 git。 2) 创建并填充 .gitignore;提交并推送 3) 恢复删除的文件(通常通过 IDEA 从 gradle.build 重新创建项目)

现在我尝试不从存储库中删除文件的新方法: 1) 创建 .git忽略 2) 使用命令:git rm -r --cached .gitignore, git rm -r --cached /.idea; ETC 3) 之后我将提交并推送。 4) 使用命令:git 添加。并再次提交和推送

但是我的命令有问题git rm -r --cached /.idea

fatal: /.idea: '/.idea' is outside repository

帮我解决这个问题=)

您想使用 git rm -r --cached ./.idea

注意 /.idea 中的 /:这将在根文件系统中查找。

我找到了更简单的方法=)

git rm -r --cached . 
 git add .
 git commit -m 'Removed all files that are in the .gitignore' 
 git push origin master