.DS_Store 是什麼
使用 Mac 的用戶可能會注意到,系統經常會自動在每個目錄生成一個隱藏的 .DS_Store 文件。.DS_Store(英文全稱 Desktop Services Store)是一種由蘋果公司的Mac OS X操作系統所創造的隱藏文件,目的在於存貯目錄的自定義屬性,例如文件們的圖標位置或者是背景色的選擇。相當於 Windows 下的 desktop.ini。
刪除 .DS_Store
如果你的項目中還沒有自動生成的 .DS_Store 文件,那麼直接將 .DS_Store 加 入到 .gitignore 文件就可以了。 如果你的項目中已經存在 .DS_Store 文件,那就需要先從項目中將其刪除,再將它加入到 .gitignore。如下:
刪除項目中的所有.DS_Store。這會跳過不在項目中的 .DS_Store
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
將 .DS_Store 加入到 .gitignore
echo .DS_Store >> ~/.gitignore
更新項目
git add --all
git commit -m '.DS_Store banished!'
如果你只需要刪除磁盤上的 .DS_Store,可以使用下面的命令來刪除當前目錄及其子目錄下的所有.DS_Store 文件
find . -name '*.DS_Store' -type f -delete
禁用或啓用自動生成
- 禁止.DS_store生成:
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
- 恢復.DS_store生成:恢復.DS_store生成:
defaults delete com.apple.desktopservices DSDontWriteNetworkStores