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


当前回答

从存储库中删除现有的.DS_Store文件:

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

添加此行:

.DS_Store

到文件.gitignore,该文件可以在存储库的顶层找到(如果文件还不存在,则创建该文件)。您可以在顶部目录中使用以下命令轻松完成此操作:

echo .DS_Store >> .gitignore

然后将文件提交到repo:

git add .gitignore
git commit -m '.DS_Store banished!'

其他回答

如果您使用的是GitHub Desktop应用程序,则此方法有效。

如果还没有,请在应用程序中打开存储库(¨O)从“存储库”选项卡中,选择“存储库设置”。转到“忽略的文件”并添加您希望忽略的文件。

从存储库中删除现有的.DS_Store文件:

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

添加此行:

.DS_Store

到文件.gitignore,该文件可以在存储库的顶层找到(如果文件还不存在,则创建该文件)。您可以在顶部目录中使用以下命令轻松完成此操作:

echo .DS_Store >> .gitignore

然后将文件提交到repo:

git add .gitignore
git commit -m '.DS_Store banished!'

使用git rm删除它们,然后将.DS_Store添加到.gitignore以阻止它们再次被添加。你也可以使用bluegravest来阻止它们一起被创造出来

有时.DS_Store文件位于远程存储库中,但在本地项目文件夹中不可见。要解决此问题,我们需要删除所有缓存的文件并再次添加。

步骤1:将其添加到.gitignore文件中。

# Ignore Mac DS_Store files
.DS_Store
**/.DS_Store

步骤2:删除缓存的文件,然后使用这些命令再次添加。

git rm -r --cached .
git add .
git commit -am "Removed git ignored files"
git push -f origin master

将此添加到文件中。gitignore

#Ignore folder mac
.DS_Store

保存并提交

git add -A
git commit -m "ignore .DS_Store"

现在你忽略了这一切