首页 > 解决方案 > Xcode 12 代码审查编辑器无法打开,因为它无法在源代码管理中找到文件

问题描述

我有一个主“app”文件夹,它是 git 存储库的根目录。在这里,我有“ios-app”文件夹,我的 Xcode xcworkspace 位于“android-app”、“backend”等其他文件夹中。令人惊讶的是,Xcode 确实显示了文件的状态(即 M 表示已修改),而我能够使用 Fetch Changes 菜单选项,但我无法使用 Xcode 提交或在代码审查编辑器中查看文件。

打开代码预览时出错:

The source control operation failed because the file “...” could not be found.
Make sure a valid file exists in the repository and try again.

在此处输入图像描述

提交时出错:

The working copy “...” failed to commit files.
error: pathspec 'app/ios-app/DataModel/EventMutations.swift' did not match any file(s) known to git

在此处输入图像描述

控制台应用程序没有什么有趣的,但以下细节可能是相关的:

[MT] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-17220/IDEKit/CommandsAndSelection/IDEMenuBuilder.m:203
Details:  Unknown submenu: "Xcode.IDEPegasusSourceEditor.MenuDefinition.SourceCodeAuxiliaryEditorMenuItem3" in menu: "Xcode.IDEPegasusSourceEditor.MenuDefinition.Editor"!
Object:   <IDEMenuBuilder>
Method:   +_menuItemForMenuItemElement:inMenuWithIdentifierUsedForDebugging:forViewController:fillingExtensionIdToMenuMap:
Thread:   <NSThread: 0x7fb3aa517540>{number = 1, name = main}
Please file a bug at https://feedbackassistant.apple.com with this warning message and any useful information you can provide.

有一次,我确实将我的文件夹从“iOS-app”重命名为“ios-app”,以排除这可能是 git 区分大小写的情况,我确实运行了git config --global core.ignorecase true,但这并不能解决问题。

我还尝试从 Xcode 的“欢迎使用 Xcode”页面中删除该项目并将它们添加回来,以防这会影响 gitpath 的确定方式。

Xcode 中的所有文件路径似乎都是正确的,并且“在文件夹中显示”选项始终有效。

我还能够在源代码管理导航中正确查看 git 项目:

在此处输入图像描述

标签: iosswiftxcodegit

解决方案


TL;DR:仔细检查本地文件夹和文件的大小写是否与远程文件夹和文件的大小写匹配。此外,请仔细检查您的本地项目是否已启用区分大小写(本地覆盖全局 git 设置),否则 git status 将假装没有任何事情发生。

就我而言,我在本地重命名iOS-appios-app,但没有将其推送到远程分支,因此 Xcode 试图找到小写版本但找不到!

似乎 Xcode 默认启用了区分大小写,而 git 可以配置。

  1. 启用本地 git 项目的 git 区分大小写:
> git config core.ignorecase
true
> git config core.ignorecase false
  1. 检查 git status 现在是否显示区分大小写的问题:
> git status

New files detected:

ios-app/
android-app/
  1. 将文件夹重命名为小写并推送。现在 git 并不容易,如果你只是这样做git mv iOS-app ios-app它不会重命名. 您需要做的是重命名iOS-app为某个临时名称,然后再改回ios-app.
> git mv iOS-app iOS-app-foo
> git mv iOS-app-foo ios-app

> git add -A
> git commit -m "Make sure that local and remote have the same case."
> git push

重新启动 Xcode,您应该一切顺利!


推荐阅读