.DS_Store still appears in git status despite being in .gitignore

后端 未结 2 817
暖寄归人
暖寄归人 2020-12-16 01:21
$ cat .gitignore 

# OSX
*/.DS_Store
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db

$ git status
On branch develop
Changes not staged         


        
相关标签:
2条回答
  • 2020-12-16 01:39

    .DS_Store still appears in git status despite being in .gitignore

    That .DS_Store file is listed as a modified file in the output of git status, which means it's currently being tracked by Git. However, Git won't ignore a file that is currently being tracked, whether it be listed in your .gitignore file or not.

    How did you get yourself in that situation? You must have inadvertently started tracking that .DS_Store file before adding the .DS_Store entry in your .gitignore.

    .gitignore itself is not modified, this version is committed.

    The list of files to ignore is not determined by any version of the .gitignore file that you may have committed, as you seem to believe. Instead, at any given time, Git uses the .gitignore file that's in your working tree (if any).

    How can I fix that?

    You need to tell Git to stop tracking that .DS_Store file, by running

    git rm --cached -- <path_to_the_.DS_Store-file>
    

    Because of the --cached flag, the problematic .DS_Store file won't be removed from your working tree, but it will not be included in your subsequent commits, and it should be properly ignored from then on.

    0 讨论(0)
  • 2020-12-16 01:55

    Make sure .DS_Store isn't in the cache:

    git rm --cached -- Assets/Sprites/.DS_Store
    
    0 讨论(0)
提交回复
热议问题