如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?
当前回答
结合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 .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 rm--缓存-f*.DS_Store$gitcommit-m“过滤器分支--索引过滤器'git rm--缓存--忽略取消匹配.DS_Store“$git推送原始主机--强制
对于那些没有得到上述任何方法帮助的人,请尝试更彻底地检查您的.gitignore,它可能会在目录和子目录之间有一些规则组合,因此烦人的.DS_Store文件不会仅在这些文件夹中被忽略。例如,您希望忽略除自定义目录中的文件夹外的gensrc文件夹,因此可以使用以下.gitignore:
.DS_Store
gensrc
!custom/**
因此,在这个设置中,忽略了任何/path/.DS_Store,而不是自定义/gensrc/.DS_Store,修复程序将把.DS_Store条目移动到.gitignore文件的底部。
如果要将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
如果您无法删除这些文件,因为它们有暂存的更改,请使用:
git rm --cached -f *.DS_Store
推荐文章
- 如何配置Mac OS X术语,使git有颜色?
- Visual Studio Code: .git文件夹/文件隐藏
- “node_modules”文件夹应该包含在git存储库中吗
- 为什么git-rebase给了我合并冲突,而我所做的只是压缩提交?
- 我如何确定文件编码在OS X?
- 使iTerm以与其他操作系统相同的方式翻译“元键”
- 错误:无法在ARM处理器上的Homebrew中安装英特尔默认前缀(/usr/local)
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- 在Mac OS X上哪里安装Android SDK ?
- GIT克隆在windows中跨本地文件系统回购
- RPC失败;卷度传输已关闭,剩余未完成的读取数据