我把这个添加到。gitignore文件
.idea/*
但无论如何,现状是:
# modified: .gitignore
# modified: .idea/.generators
# modified: .idea/dovezu.iml
# modified: .idea/misc.xml
# modified: .idea/workspace.xml
我做错了什么?
我甚至在全局变量~/.gitignore_global中添加了.idea/*
但是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/*来忽略一个目录。您可以在.gitignore手册页上找到关于模式的更多信息。
来自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.
索引更新——skip-worktree
忽略配置文件的特定git选项是:
$ git update-index --skip-worktree <filepath>
注意,不需要在.gitignore中添加任何东西。
要取消此设置,例如当配置文件的通用结构发生更改时:
$ git update-index --no-skip-worktree <filepath>
——skip-worktree用于指示git永远不要将文件更改索引到特定的文件。这可能是因为开发人员通常需要在本地更改文件以测试项目。例如,如果主存储库上游托管了一个可用于生产的配置文件,那么应该防止对该文件的意外提交更改。
而——assume-unchanged则假设开发人员永远不应该更改该文件。这个标志仅仅是为了提高git的性能,不改变像软件开发工具包(SDK)组件这样的文件夹。