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


当前回答

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

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

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

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

其他回答

以下方法对我来说效果最好。处理了不匹配的文件,以及本地修改的文件。作为参考,这是在运行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

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

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

从存储库中删除现有的.DS_Store文件:

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

添加此行:

.DS_Store

到文件.gitignore,该文件可以在存储库的顶层找到(如果文件还不存在,则创建该文件)。您可以在顶部目录中使用以下命令轻松完成此操作:

echo .DS_Store >> .gitignore

然后将文件提交到repo:

git add .gitignore
git commit -m '.DS_Store banished!'

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

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

然后将.DS_Store添加到.gitignore

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