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

我该如何修复?


当前回答

.gitignore文件应如下所示:

# Ignore Mac DS_Store files
.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

提交并推送

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

步骤1,删除所有*.DS_store文件。一个人可以跑

git rm -f *.DS_Store

但是要注意,如果你有拼写错误,rm-f可能会有点危险!第二步:添加

*.DS_Store
.DS_Store

到。gitignore。这对我有用!

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