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


当前回答

使用此命令删除现有文件:

find . -name '*.DS_Store' -type f -delete

然后将.DS_Store添加到.gitignore

其他回答

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

$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

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

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

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

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

删除忽略的文件:

(.DS_Store)

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

在某些情况下,您可能还需要全局忽略某些文件。对我来说,.DS_Store就是其中之一。以下是操作方法:

git config --global core.excludesfile /Users/mat/.gitignore

(或您选择的任何文件)

然后像repo的.gitignore一样编辑文件。注意,我认为必须使用绝对路径。