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


当前回答

$ git commit -m "filter-branch --index-filter 'git rm --cached --ignore-unmatch .DS_Store"
$ git push origin master --force

其他回答

如果您无法删除这些文件,因为它们有暂存的更改,请使用:

git rm --cached -f *.DS_Store

将此添加到文件中。gitignore

#Ignore folder mac
.DS_Store

保存并提交

git add -A
git commit -m "ignore .DS_Store"

现在你忽略了这一切

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

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

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

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

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

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

我做了:

git checkout -- ../.DS_Store

(#将本地更改(永久)丢弃到文件)而且效果很好!