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


当前回答

我发现snipplr的下面一行在擦除所有.DS_Store方面做得最好,包括一个具有本地修改的行。

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

--cached选项,保留本地.DS_Store,因为它无论如何都会被复制。

正如上面提到的,将.DS_Store添加到项目根目录的.gitignore文件中。那么它将不再在你的视线中(回购)。

其他回答

从存储库中删除现有的.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 checkout -- ../.DS_Store

(#将本地更改(永久)丢弃到文件)而且效果很好!

这将起作用:

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

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

删除忽略的文件:

(.DS_Store)

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

结合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