.gitignore删除每个文件夹和子文件夹中的所有.DS_Store文件 [英] .gitignore all the .DS_Store files in every folder and subfolder
问题描述
我已将.DS_Store添加到.gitignore文件中,但似乎它只是忽略根目录中的.DS_Store,而不是忽略每个文件夹和子文件夹中的.DS_Store.
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.
我该如何解决?
推荐答案
我认为您遇到的问题是,在某些较早的提交中,您不小心将.DS_Store
文件添加到了存储库中.当然,一旦在存储库中跟踪了文件,即使它与适用的.gitignore文件中的条目匹配,也将继续跟踪该文件.
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.
您必须手动删除添加到存储库中的.DS_Store
文件.您可以使用
You have to manually remove the .DS_Store
files that were added to your repository. You can use
git rm --cached .DS_Store
一旦删除,git应该忽略它.您在根.gitignore
根文件中仅需要以下行:.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
仅从当前目录中删除.DS_Store
.您可以使用
removes only .DS_Store
from the current directory. You can use
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
从存储库中删除所有.DS_Stores
.
毡尖提示:由于您可能永远不想包含.DS_Store
文件,因此请制定全局规则.首先,在某处创建一个全局.gitignore
文件,例如
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
现在告诉git将其用于所有存储库:
Now tell git to use it for all repositories:
git config --global core.excludesfile ~/.gitignore_global
此页面帮助我回答了您的问题.
This page helped me answer your question.
这篇关于.gitignore删除每个文件夹和子文件夹中的所有.DS_Store文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!