如何从Git存储库中删除那些烦人的Mac OS X.DS_Store文件?
当前回答
结合benzado和webmat的答案,使用git rm进行更新,不会对发现的不在repo中的文件失败,并使其可为任何用户粘贴:
# remove any existing files from the repo, skipping over ones not in repo
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# specify a global exclusion list
git config --global core.excludesfile ~/.gitignore
# adding .DS_Store to that list
echo .DS_Store >> ~/.gitignore
其他回答
如果您使用的是GitHub Desktop应用程序,则此方法有效。
如果还没有,请在应用程序中打开存储库(¨O)从“存储库”选项卡中,选择“存储库设置”。转到“忽略的文件”并添加您希望忽略的文件。
如果您无法删除这些文件,因为它们有暂存的更改,请使用:
git rm --cached -f *.DS_Store
结合benzado和webmat的答案,使用git rm进行更新,不会对发现的不在repo中的文件失败,并使其可为任何用户粘贴:
# remove any existing files from the repo, skipping over ones not in repo
find . -name .DS_Store -print0 | xargs -0 git rm --ignore-unmatch
# specify a global exclusion list
git config --global core.excludesfile ~/.gitignore
# adding .DS_Store to that list
echo .DS_Store >> ~/.gitignore
出于某种原因,以上这些都不适用于我的mac。
我的解决方案来自终端运行:
rm .DS_Store
然后运行以下命令:
git pull origin master
解决此问题的最佳解决方案是全局忽略系统上所有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
编辑:
删除了图标,因为它们可能需要作为应用程序资产提交。