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


当前回答

对于那些没有得到上述任何方法帮助的人,请尝试更彻底地检查您的.gitignore,它可能会在目录和子目录之间有一些规则组合,因此烦人的.DS_Store文件不会仅在这些文件夹中被忽略。例如,您希望忽略除自定义目录中的文件夹外的gensrc文件夹,因此可以使用以下.gitignore:

.DS_Store
gensrc
!custom/**

因此,在这个设置中,忽略了任何/path/.DS_Store,而不是自定义/gensrc/.DS_Store,修复程序将把.DS_Store条目移动到.gitignore文件的底部。

其他回答

结合benzado和webmat的答案,使用git rm进行更新,不会对发现的不在repo中的文件失败,并使其可为任何用户粘贴:

# remove any existing files from the repo, skipping over ones not in repo
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# specify a global exclusion list
git config --global core.excludesfile ~/.gitignore
# adding .DS_Store to that list
echo .DS_Store >> ~/.gitignore

使用touch.gitignore命令创建.gitignore文件

并在其中添加以下行

.DS_Store

保存.gitignore文件,然后将其推送到git repo中。

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

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

rm .DS_Store

然后运行以下命令:

git pull origin master

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

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

我参加晚会有点晚了,但我有一个好答案。要删除.DS_Store文件,请在终端窗口中使用以下命令,但要非常小心地使用“find”删除文件。在-name选项中使用特定名称是更安全的使用方法之一:

cd directory/above/affected/workareas
find . -name .DS_Store -delete

如果您想简单地在前后列出它们,可以省略“-delete”。这会让你放心,他们走了。

关于~/.gitignore_global建议:请注意这里。你想把这个漂亮的文件放在每个工作区的顶层并提交它,这样任何克隆您的repo的人都将从中受益。