我将其添加到 .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/