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


当前回答

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

git rm --cached -f *.DS_Store

其他回答

打开终端并键入“cd<ProjectPath>”

删除现有文件:查找-name.DS_Store-print0|xargs-0 git rm-f--忽略取消匹配nano.git忽略添加此.DS_Store键入“ctrl+x”类型“y”输入以保存文件git-add.gitignoregitcommit-m'.DS_Store已删除。'

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

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

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

rm .DS_Store

然后运行以下命令:

git pull origin master

步骤1

这将删除目录(包括子目录)中的每个.DS_Store文件

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

步骤2

将此添加到.gitignore以防止根目录和每个子目录中的任何DS_Store文件进入git!

**/.DS_Store

从git文档中:

前导“**”后接斜杠表示所有目录中的匹配。例如,“**/foo”与任何位置的文件或目录“foo”匹配,与模式“foo“相同。“**/foo/bar”匹配直接位于目录“foo”下的文件或目录“bar”。

从存储库中删除现有的.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!'