Git 忽略 .DS_Store 文件
Mac 上的 .DS_Store 文件
.DS_Store 文件,是用于存放目录自定义属性(如图表、位置属性)等元数据信息的系统文件,由 Finder 自动创建。
在 Mac 上,所有 . 开头的文件或文件夹默认都是隐藏的(可以使用 Command + Shift + . 显示所有隐藏文件)。
一、Git 忽略文件的配置(.gitignore)
在 Git 工程根目录中中新建 .gitignore 文件,在文件中添加:
1
2
3
.DS_Store
**/.DS_Store
.DS_Store?
二、全局设置忽略
查看当前的 Git 配置情况
1
2
3
git config --list
或
cat ~/.gitconfig
创建 .gitignore_global 文件,把需要全局忽略的文件路径写入其中。
创建文件
1
touch ~/.gitignore_global
打开文件
1
open ~/.gitignore_global
文件中写入
1
2
3
.DS_Store
**/.DS_Store
.DS_Store?
对 Git 进行全局设置,让 Git 忽略 .gitignore_global 中的所有文件
1
git config --global core.excludesfile ~/.gitignore_global
三、批量删除仓库中已有的 .DS_Store
1
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
本文由作者按照
CC BY 4.0
进行授权