I've added .DS_Store to the .gitignore file, but it seems that it is only ignoring .DS_Store in the root directory, not in every folder and subfolder.
How do I fix this?
DS_Store file in your directories. It's not a big issue, but often you need to exclude these files explicitly in your . gitignore file, to prevent any unnecessary files in your commit. You may want to ignore this file globally, so next time you don't need to add it to your project's ignore list.
gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.
A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .
I think the problem you're having is that in some earlier commit, you've accidentally added .DS_Store
files to the repository. Of course, once a file is tracked in your repository, it will continue to be tracked even if it matches an entry in an applicable .gitignore file.
You have to manually remove the .DS_Store
files that were added to your repository. You can use
git rm --cached .DS_Store
Once removed, git should ignore it. You should only need the following line in your root .gitignore
file: .DS_Store
. Don't forget the period!
git rm --cached .DS_Store
removes only .DS_Store
from the current directory. You can use
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
to remove all .DS_Stores
from the repository.
Felt tip: Since you probably never want to include .DS_Store
files, make a global rule. First, make a global .gitignore
file somewhere, e.g.
echo .DS_Store >> ~/.gitignore_global
Now tell git to use it for all repositories:
git config --global core.excludesfile ~/.gitignore_global
This page helped me answer your question.
Add**/.DS_Store
into .gitignore
for the sub directory
If .DS_Store
already committed:
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
To ignore them in all repository: (sometimes it named ._.DS_Store
)
echo ".DS_Store" >> ~/.gitignore_global echo "._.DS_Store" >> ~/.gitignore_global echo "**/.DS_Store" >> ~/.gitignore_global echo "**/._.DS_Store" >> ~/.gitignore_global git config --global core.excludesfile ~/.gitignore_global
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With