如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?


当前回答

使用此命令删除现有文件:

find . -name '*.DS_Store' -type f -delete

然后将.DS_Store添加到.gitignore

其他回答

解决此问题的最佳解决方案是全局忽略系统上所有git repo中的这些文件。这可以通过创建一个全局gitignore文件来完成,如:

vi ~/.gitignore_global

添加忽略文件的规则,如:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

现在,将此文件添加到全局git配置中:

git config --global core.excludesfile ~/.gitignore_global

编辑:

删除了图标,因为它们可能需要作为应用程序资产提交。

如果您无法删除这些文件,因为它们有暂存的更改,请使用:

git rm --cached -f *.DS_Store

使用touch.gitignore命令创建.gitignore文件

并在其中添加以下行

.DS_Store

保存.gitignore文件,然后将其推送到git repo中。

删除忽略的文件:

(.DS_Store)

$ find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch

初始化存储库时,跳过包含

-u

这不应该是个问题。