git still shows files as modified after adding to .gitignore

前端 未结 5 2313
闹比i
闹比i 2020-12-12 09:27

i\'m adding this to .gitignore file

.idea/*

but anyway the status is:

#       modified:   .gitignore
#             


        
5条回答
  •  自闭症患者
    2020-12-12 09:55

    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.
    

提交回复
热议问题