如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?


当前回答

对于那些没有得到上述任何方法帮助的人,请尝试更彻底地检查您的.gitignore,它可能会在目录和子目录之间有一些规则组合,因此烦人的.DS_Store文件不会仅在这些文件夹中被忽略。例如,您希望忽略除自定义目录中的文件夹外的gensrc文件夹,因此可以使用以下.gitignore:

.DS_Store
gensrc
!custom/**

因此,在这个设置中,忽略了任何/path/.DS_Store,而不是自定义/gensrc/.DS_Store,修复程序将把.DS_Store条目移动到.gitignore文件的底部。

其他回答

打开终端并键入“cd<ProjectPath>”

删除现有文件:查找-name.DS_Store-print0|xargs-0 git rm-f--忽略取消匹配nano.git忽略添加此.DS_Store键入“ctrl+x”类型“y”输入以保存文件git-add.gitignoregitcommit-m'.DS_Store已删除。'

这对我很有用,上面有两个答案:

$git rm--缓存-f*.DS_Store$gitcommit-m“过滤器分支--索引过滤器'git rm--缓存--忽略取消匹配.DS_Store“$git推送原始主机--强制

我必须将上面的git rm更改为git rm才能使其工作:

find . -depth -name '.DS_Store' -exec git rm --cached '{}' \; -print
$ git commit -m "filter-branch --index-filter 'git rm --cached --ignore-unmatch .DS_Store"
$ git push origin master --force

我发现snipplr的下面一行在擦除所有.DS_Store方面做得最好,包括一个具有本地修改的行。

find . -depth -name '.DS_Store' -exec git-rm --cached '{}' \; -print

--cached选项,保留本地.DS_Store,因为它无论如何都会被复制。

正如上面提到的,将.DS_Store添加到项目根目录的.gitignore文件中。那么它将不再在你的视线中(回购)。