Skip to content

Git 设置全局忽略 .gitignore_global

  • https://git-scm.com/docs/gitignore
  • https://git-scm.com/docs/git-config

Git 设置全局忽略 .gitignore_global

# 使用 `vim` 在家目录下新建名为 `.gitignore_global` 的文件
vim ~/.gitignore_global
# 
git config --global core.excludesfile ~/.gitignore_global
# 查看 Git 当前配置情况
git config --list

.gitignore_global 的忽略匹配规则:

# for Mac OS X System Files
**/.DS_Store
.*.swp
Thumbs.db

可以通过 gitignore.io 来为项目自动生成必要的 .gitignore 忽略匹配规则。

# Created by https://www.toptal.com/developers/gitignore/api/macos
# Edit at https://www.toptal.com/developers/gitignore?templates=macos

### macOS ###
# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### macOS Patch ###
# iCloud generated files
*.icloud

# End of https://www.toptal.com/developers/gitignore/api/macos

删除 repo 中已有的 .DS_Store

find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# 对于已经提交的内容,希望 git 能够忽略,但同时并不会删除本地文件
git rm -r --cached $file_path