15
$ 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 for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   Assets/Sprites/.DS_Store

no changes added to commit (use "git add" and/or "git commit -a")

There are more unrelated files in .gitignore and status message right now, but .gitignore itself is not modified, this version is committed.

How can I fix that?

Max Yankov
  • 12,551
  • 12
  • 67
  • 135
  • possible duplicate of [Git diff doesn't ignore specified files in .gitignore](http://stackoverflow.com/questions/17820056/git-diff-doesnt-ignore-specified-files-in-gitignore) –  Sep 06 '14 at 13:33

2 Answers2

21

Make sure .DS_Store isn't in the cache:

git rm --cached -- Assets/Sprites/.DS_Store
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
17

.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.

jub0bs
  • 60,866
  • 25
  • 183
  • 186
  • I did it without the `--`, and instead just the filepath `git rm --cached ./DS_Store` and it still worked. What does the `--` do? – ahnbizcad Jul 03 '15 at 05:13
  • @ahnbizcad See http://stackoverflow.com/questions/22750028/in-git-what-does-dash-dash-mean?lq=1 – jub0bs Jul 03 '15 at 07:45
  • 1
    '--' ensures things go smoothly... (E.g. if your file name starts with a '-' character) – ahnbizcad Jul 04 '15 at 09:20