Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Remove .DS_Store files from a Git repository?

How can I remove those annoying Mac OS X .DS_Store files from a Git repository?

like image 956
John Topley Avatar asked Sep 20 '08 09:09

John Topley


People also ask

What is .DS_Store file in Git?

The . DS_Store file is used to store Finder information about that folder, so it's has no use in a git repo.


3 Answers

Remove existing .DS_Store files from the repository:

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Add this line:

.DS_Store

to the file .gitignore, which can be found at the top level of your repository (or create the file if it isn't there already). You can do this easily with this command in the top directory:

echo .DS_Store >> .gitignore

Then commit the file to the repo:

git add .gitignore
git commit -m '.DS_Store banished!'
like image 182
benzado Avatar answered Oct 28 '22 06:10

benzado


Combining benzado and webmat's answers, updating with git rm, not failing on files found that aren't in repo, and making it paste-able generically for any user:

# remove any existing files from the repo, skipping over ones not in repo
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# specify a global exclusion list
git config --global core.excludesfile ~/.gitignore
# adding .DS_Store to that list
echo .DS_Store >> ~/.gitignore
like image 37
Turadg Avatar answered Oct 28 '22 08:10

Turadg


The best solution to tackle this issue is to Globally ignore these files from all the git repos on your system. This can be done by creating a global gitignore file like:

vi ~/.gitignore_global

Adding Rules for ignoring files like:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

Now, add this file to your global git config:

git config --global core.excludesfile ~/.gitignore_global

Edit:

Removed Icons as they might need to be committed as application assets.

like image 196
Nerve Avatar answered Oct 28 '22 06:10

Nerve