使用 Mac 的用戶可能會注意到,系統常常會自動在每一個目錄生成一個隱藏的 .DS_Store 文件。.DS_Store(英文全稱 Desktop Services Store)是一種由蘋果公司的Mac OS X操做系統所創造的隱藏文件,目的在於存貯目錄的自定義屬性,例如文件們的圖標位置或者是背景色的選擇。至關於 Windows 下的 desktop.ini。html
若是你的項目中尚未自動生成的 .DS_Store 文件,那麼直接將 .DS_Store 加入到 .gitignore 文件就能夠了。若是你的項目中已經存在 .DS_Store 文件,那就須要先從項目中將其刪除,再將它加入到 .gitignore。以下:git
#刪除項目中的全部.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 文件:app
find . -name '*.DS_Store' -type f -delete
注意:若是使用GitHub Desktop來建立repository以及publish repository,那麼客戶端會本身處理此問題,客戶端處理此問題的方式就是刪除此文件。參考博客spa
禁止.DS_store生成:操作系統
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE
恢復.DS_store生成:恢復.DS_store生成:code
defaults delete com.apple.desktopservices DSDontWriteNetworkStores