如何从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

其他回答

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

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

(或您选择的任何文件)

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

删除忽略的文件:

(.DS_Store)

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

这将起作用:

find . -name "*.DS_Store" -type f -exec git-rm {} \;

它将删除所有名称以.DS_Store结尾的文件,包括._。DS_存储。

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

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

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

git rm --cached -f *.DS_Store