我已经将.DS_Store添加到.gitignore文件中,但它似乎只是忽略了根目录中的.DS_Store,而不是每个文件夹和子文件夹中的.DS-Store。

我该如何修复?


当前回答

将*.DS_Store添加到.gitignore文件中。这对我来说很好

其他回答

只需将其放在.gitignore中的新行中

**/.DS_Store

来自git文档

前导“**”后接斜杠表示所有目录中的匹配。例如,“**/foo”与任何位置的文件或目录“foo”匹配,与模式“foo“相同。“**/foo/bar”匹配直接位于目录“foo”下的文件或目录“bar”。

您还可以将--cached标志添加到auco的答案中,以维护本地.DS_store文件,正如Edward Newell在最初的答案中所提到的那样。修改后的命令如下:find-name.DS_Store-print0|xargs-0 git rm--cached--忽略取消匹配。。干杯,谢谢!

步骤:1)使用此命令删除现有文件

查找-name.DS_Store-print0|xargs-0 git rm-f--忽略取消匹配

步骤:2)在.gitignore文件中添加.DS_Store

步骤:3)在.gitignore中提交更改git-add.gitignoregitcommit-m“已删除.DS_Store”

如果.DS_Store从未添加到git存储库中,只需将其添加到.gitignore文件中即可。

如果没有,请创建一个名为

.gitignore

在应用程序的根目录中,只需编写

**/.DS_Store

这将永远不会允许.DS_Store文件潜入您的git中。

但是,如果它已经存在,请在终端中写入:

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

然后提交并推送更改以从远程存储库中删除.DS_Store:

git commit -m "Remove .DS_Store from everywhere"

git push origin master

现在将.DS_Store添加到.gitignore文件中,然后再次提交并推送最后两段代码(gitcommit…,gitpush…)

$git rm./*。DS_Store-从git中删除所有.DS_Store$echo\.DS_Store>>.gitignore-忽略.DS_Store

提交并推送