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


当前回答

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

其他回答

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

git rm --cached -f *.DS_Store

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

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

rm .DS_Store

然后运行以下命令:

git pull origin master

这将起作用:

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

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

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

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

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

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

然后将.DS_Store添加到.gitignore