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


当前回答

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

git rm --cached -f *.DS_Store

其他回答

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

我必须将上面的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的人都将从中受益。

将此添加到文件中。gitignore

#Ignore folder mac
.DS_Store

保存并提交

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

现在你忽略了这一切

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

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

然后将.DS_Store添加到.gitignore