Xcode 12 代码审查编辑器无法打开,因为它无法在源代码管理中找到文件

Zor*_*ayr 6 git xcode ios swift

我有一个主“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.
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

提交时出错:

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

在此处输入图片说明

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

[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.
Run Code Online (Sandbox Code Playgroud)

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

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

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

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

在此处输入图片说明

Zor*_*ayr 5

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

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

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

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

New files detected:

ios-app/
android-app/
Run Code Online (Sandbox Code Playgroud)
  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
Run Code Online (Sandbox Code Playgroud)

重新启动 Xcode,你应该就可以开始了!