如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?
当前回答
我做了:
git checkout -- ../.DS_Store
(#将本地更改(永久)丢弃到文件)而且效果很好!
其他回答
以下方法对我来说效果最好。处理了不匹配的文件,以及本地修改的文件。作为参考,这是在运行git 1.7.4.4的Mac 10.7系统上。
查找并删除:
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch -f
我还通过设置全局core.excludsfile来全局忽略.DS_Store。
首先,创建文件(如果还不存在):
touch ~/.gitignore
然后添加以下行并保存:
.DS_Store
现在配置git以全局尊重文件:
git config --global core.excludesfile ~/.gitignore
结合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
这将起作用:
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
我必须将上面的git rm更改为git rm才能使其工作:
find . -depth -name '.DS_Store' -exec git rm --cached '{}' \; -print
推荐文章
- 访问限制:'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合并与强制覆盖