Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore all the .DS_Store files in every folder and subfolder

Tags:

gitignore

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?

like image 735
vickyqiu Avatar asked Aug 23 '13 02:08

vickyqiu


People also ask

Should you add DS_Store to Gitignore?

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.

Does .gitignore work in subdirectories?

gitignore file is usually placed in the repository's root directory. However, you can create multiple . gitignore files in different subdirectories in your repository.

Does Gitignore need to be in every folder?

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 .


2 Answers

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.

like image 152
Edward Newell Avatar answered Oct 11 '22 00:10

Edward Newell


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 
like image 45
ronald8192 Avatar answered Oct 10 '22 22:10

ronald8192