How can I remove those annoying Mac OS X .DS_Store files from a Git repository?
This will work:
find . -name *.DS_Store -type f -exec git-rm {} \;
delete them using git-rm
, and then add .DS_Store to .gitignore
to stop them getting added again. You can also use blueharvest to stop them getting created all together
Remove existing files from the repository:
find . -name .DS_Store -print0 | xargs -0 git-rm
Add the line
.DS_Store
to the file .gitignore
, which can be found at the top level of your repository (or created if it isn't there already). Then
git add .gitignore
git commit -m ".DS_Store banished!"
In some situations you may also want to ignore some files globally. For me, .DS_Store is one of them. Here's how:
git config --global core.excludesfile = /Users/mat/.gitignore
(Or any file of your choice)
Then edit the file just like a repo's .gitignore. Note that I think you have to use an absolute path.
I found that the following line from snipplr does best on wiping all .DS_Store, including one that has local modifications.
find . -depth -name '.DS_Store' -exec git-rm --cached '{}' \; -print
--cached option, keeps your local .DS_Store since it gonna be reproduced anyway.
And just like mentioned all above, add .DS_Store to .gitignore file on the root of your project. Then it will be no longer in your sight (of repos).
I had to change git-rm to git rm in the above to get it to work:
find . -depth -name '.DS_Store' -exec git rm --cached '{}' \; -print