在添加到.gitignore之后,git仍然显示文件被修改 [英] git still shows files as modified after adding to .gitignore

查看:1498
本文介绍了在添加到.gitignore之后,git仍然显示文件被修改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此项添加到 .gitignore 文件中

  .idea / * 

但无论如何,状态是:

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

我做错了什么?
i甚至将.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 / * 来忽略一个目录。您可以在 .gitignore 手册页上找到关于模式的更多信息。 a>。




来自 git-rm 手册页

   -  cached 
使用此选项可以仅从指数。
无论是否修改工作树文件,都将被单独保留。


i'm adding this to .gitignore file

.idea/*

but anyway the status is:

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

what am i doing wrong ? i even added .idea/* to the global ~/.gitignore_global but git status, anyway shows me:

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

解决方案

Your .gitignore is working, but it still tracks the files because they were already in the index.

To stop this you have to do : git rm -r --cached .idea/

When you commit the .idea/ directory will be removed from your git repository and the following commits will ignore the .idea/ directory.

PS: You could use .idea/ instead of .idea/* to ignore a directory. You can find more info about the patterns on the .gitignore man page.


Helpful quote from the git-rm man page

--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仍然显示文件被修改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆