如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?
当前回答
使用此命令删除现有文件:
find . -name '*.DS_Store' -type f -delete
然后将.DS_Store添加到.gitignore
其他回答
我参加晚会有点晚了,但我有一个好答案。要删除.DS_Store文件,请在终端窗口中使用以下命令,但要非常小心地使用“find”删除文件。在-name选项中使用特定名称是更安全的使用方法之一:
cd directory/above/affected/workareas
find . -name .DS_Store -delete
如果您想简单地在前后列出它们,可以省略“-delete”。这会让你放心,他们走了。
关于~/.gitignore_global建议:请注意这里。你想把这个漂亮的文件放在每个工作区的顶层并提交它,这样任何克隆您的repo的人都将从中受益。
步骤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”。
结合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文件位于远程存储库中,但在本地项目文件夹中不可见。要解决此问题,我们需要删除所有缓存的文件并再次添加。
步骤1:将其添加到.gitignore文件中。
# Ignore Mac DS_Store files
.DS_Store
**/.DS_Store
步骤2:删除缓存的文件,然后使用这些命令再次添加。
git rm -r --cached .
git add .
git commit -am "Removed git ignored files"
git push -f origin master
解决此问题的最佳解决方案是全局忽略系统上所有git repo中的这些文件。这可以通过创建一个全局gitignore文件来完成,如:
vi ~/.gitignore_global
添加忽略文件的规则,如:
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
现在,将此文件添加到全局git配置中:
git config --global core.excludesfile ~/.gitignore_global
编辑:
删除了图标,因为它们可能需要作为应用程序资产提交。
推荐文章
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 为什么在Mac OS X v10.9 (Mavericks)的终端中apt-get功能不起作用?
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- “你有邮件”的消息在终端,os X
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- Mac OS X中的环境变量
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖