3

In git ignore list I have:

build/**
.DS_Store

After updating some files git status shows:

modified:   db/main/res/.DS_Store

I did not expect to show that .DS_Store is modified because it is in ignore list. Working directory or project root is ~/myproj.

How to fix this problem?

scrowler
  • 24,273
  • 9
  • 60
  • 92
ace
  • 11,526
  • 39
  • 113
  • 193
  • the `.DS_Store` in your gitignore would only apply to the root directory. I'm not sure how it works, but maybe try `**/.DS_Store` as well – scrowler Jan 18 '16 at 03:25
  • As mentioned below, the wildcard shouldn't be necessary. ".DS_Store" will prevent the file being tracked in all directories. – tomp Jan 18 '16 at 04:34

1 Answers1

6

The ".DS_Store" entry in your .gitignore file will prevent new .DS_Store files being tracked by Git when you run git add.

It sounds like the problem in your case is that the .DS_Store file was being tracked by Git before you included .DS_Store in the .gitignore file.

So all you need to do is remove the .DS_Store file from the repo with git rm --cached db/main/res/.DS_Store and it won't be tracked from then on.

(added --cached following Edward's comment).

tomp
  • 613
  • 6
  • 24
  • Can you reiterate this (rather good!) answer, on how to remove ALL .DS_Store files in my repo? sadly, there are many, and since they're hidden, enlisting them and removing them one by one should be tedious on a large project. I'm sure there is a simple git command for this? – Motti Shneor Jul 14 '19 at 07:34
  • Thanks Motti, in this case the `git rm` command needs to be run across subdirectories. `find . -name .DS_Store -print0 | xargs -0 git rm -f --cached --ignore-unmatch` should do it (see https://stackoverflow.com/questions/107701/how-can-i-remove-ds-store-files-from-a-git-repository). Then run `git commit` to commit the changes to the repo. – tomp Jul 15 '19 at 14:06