如何从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 1.7.4.4的Mac 10.7系统上。

查找并删除:

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

我还通过设置全局core.excludsfile来全局忽略.DS_Store。

首先,创建文件(如果还不存在):

touch ~/.gitignore

然后添加以下行并保存:

.DS_Store

现在配置git以全局尊重文件:

git config --global core.excludesfile ~/.gitignore

这将起作用:

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

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

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

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

然后将.DS_Store添加到.gitignore

出于某种原因,以上这些都不适用于我的mac。

我的解决方案来自终端运行:

rm .DS_Store

然后运行以下命令:

git pull origin master

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

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

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

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