如何从Git存储库中删除那些烦人的Mac OS X.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已删除。'

其他回答

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

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

然后将.DS_Store添加到.gitignore

在某些情况下,您可能还需要全局忽略某些文件。对我来说,.DS_Store就是其中之一。以下是操作方法:

git config --global core.excludesfile /Users/mat/.gitignore

(或您选择的任何文件)

然后像repo的.gitignore一样编辑文件。注意,我认为必须使用绝对路径。

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

git rm --cached -f *.DS_Store

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

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

如果要将DS_Store文件删除到每个文件夹和子文件夹:如果已提交DS_Store:

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

通过以下方式忽略它们:

echo ".DS_Store" >> ~/.gitignore_global
echo "._.DS_Store" >> ~/.gitignore_global
echo "**/.DS_Store" >> ~/.gitignore_global
echo "**/._.DS_Store" >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global