添加到 .gitignore 后,git 仍然显示已修改的文件

标签 git gitignore

我将其添加到 .gitignore 文件

.idea/*

但无论如何状态是:

#       modified:   .gitignore
#       modified:   .idea/.generators
#       modified:   .idea/dovezu.iml
#       modified:   .idea/misc.xml
#       modified:   .idea/workspace.xml

我做错了什么? 我什至将 .idea/* 添加到全局 ~/.gitignore_global 但是 git 状态,无论如何显示我:

#       modified:   .gitignore
#       modified:   .idea/.generators
#       modified:   .idea/dovezu.iml
#       modified:   .idea/misc.xml
#       modified:   .idea/workspace.xml

最佳答案

您的 .gitignore 正在运行,但它仍会跟踪文件,因为它们已经在索引中。

要停止这个你必须做:git rm -r --cached .idea/

当您提交时,.idea/ 目录将从您的 git 存储库中删除,并且后续提交将忽略 .idea/ 目录。

PS:您可以使用 .idea/ 而不是 .idea/* 来忽略目录。您可以在 the .gitignore man page 上找到有关模式的更多信息.


来自 git-rm 手册页的有用引述

--cached
    Use this option to unstage and remove paths only from the index. 
    Working tree files, whether modified or not, will be left alone.

关于添加到 .gitignore 后,git 仍然显示已修改的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9750606/

相关文章:

git filter-branch 导致断开连接的历史记录 : how to get rid of the old commits?

git - 有没有一种简单的方法可以让 master 中的每个功能获得一次提交,而不是使用 squash 进行 rebase

git - 使用 .gitignore 忽略不同文件夹中的相同文件

node.js - .gitignore 不忽略 node_modules/folder

git - blackberry10 c++ .gitignore?

git - 什么是 Git,我为什么需要它?

git - git filter-branch 删除大量文件

linux - 如何使用 DockerFile 从 git repo 获取源代码

windows - 在 Windows 上忽略 Git 存储库中的目录

git - 如何包含父 .gitignore 排除的文件夹?