如何从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!'
其他回答
结合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
我参加晚会有点晚了,但我有一个好答案。要删除.DS_Store文件,请在终端窗口中使用以下命令,但要非常小心地使用“find”删除文件。在-name选项中使用特定名称是更安全的使用方法之一:
cd directory/above/affected/workareas
find . -name .DS_Store -delete
如果您想简单地在前后列出它们,可以省略“-delete”。这会让你放心,他们走了。
关于~/.gitignore_global建议:请注意这里。你想把这个漂亮的文件放在每个工作区的顶层并提交它,这样任何克隆您的repo的人都将从中受益。
这对我很有用,上面有两个答案:
$git rm--缓存-f*.DS_Store$gitcommit-m“过滤器分支--索引过滤器'git rm--缓存--忽略取消匹配.DS_Store“$git推送原始主机--强制
我发现snipplr的下面一行在擦除所有.DS_Store方面做得最好,包括一个具有本地修改的行。
find . -depth -name '.DS_Store' -exec git-rm --cached '{}' \; -print
--cached选项,保留本地.DS_Store,因为它无论如何都会被复制。
正如上面提到的,将.DS_Store添加到项目根目录的.gitignore文件中。那么它将不再在你的视线中(回购)。
将此添加到文件中。gitignore
#Ignore folder mac
.DS_Store
保存并提交
git add -A
git commit -m "ignore .DS_Store"
现在你忽略了这一切