error: The following untracked working tree files would be overwritten by merge: .DS_Store

error: The following untracked working tree files would be overwritten by merge: .DS_Store

我在 mac 上有一个 git 存储库,当我在终端中使用 git status 时,它显示

On branch master
nothing to commit, working directory clean

当我尝试从存储库中提取更改时 git pull repositoryName master

error: The following untracked working tree files would be overwritten by merge:
.DS_Store
Please move or remove them before you can merge.

所以我尝试用 git rm .DS_Store 删除它,但它说

fatal: pathspec '.DS_Store' did not match any files

然后我尝试删除缓存文件并使用 git rm --cached . -rgit add . 再次添加它,并使用 .gitignore 指令忽略 .DS_Store 但是问题仍然存在。

我尝试了很多我在不同帖子上看到的命令,但都没有成功。任何帮助将不胜感激。

.DS_Store

是一个 Mac 相关文件,每次您触摸某个目录时都会创建它(如果我没记错的话,它用于索引)。

所以,首先你没有。然后你尝试将一些 files/folders 带入你的目录(因此它被创建 - 破坏你的 pull 命令)。

在你的 repo 目录中创建一个名为 .gitignore 的文件,里面只有一行(到目前为止).DS_Store.这应该可以解决您的问题。

当你mkdir你的文件夹时,你可以输入这个命令git init然后拉取。那将解决你的问题。

我通过从 git 原始存储库中删除 .DS_Store 解决了这个问题。

rm .DS_Store

我运行 repo 文件夹上的上述命令。终于可以从 git 中拉出来了。 我建议您在 .gitignore 文件中添加 .DS_Store