【问题标题】:Xcode 12 code review editor fails to open because it's unable to find the file in source controlXcode 12 代码审查编辑器无法打开,因为它无法在源代码管理中找到文件
【发布时间】:2021-01-29 10:14:04
【问题描述】:

我有一个主“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 项目:

【问题讨论】:

  • 文件存在于本地还是远程?另外,您的目录中是否有该文件的特殊字符?包括空格?由于我的目录中有空间,我过去曾把它扔掉。
  • 本地和远程都没有特殊字符以及我的文件。我正在从本地文件夹中打开项目。
  • 啊...刚发现我的遥控器和本地的情况不同,不知道这会不会影响它?!
  • 是的,绝对会影响它。最好的办法是隐藏您的更改,然后拉动并尝试将这些更改拼凑在一起。希望你不是 1000 行,哈哈。
  • 您是否忘记将上游设置为原点?

标签: ios swift xcode git


【解决方案1】:

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

就我而言,我在本地将 iOS-app 重命名为 ios-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,一切顺利!

【讨论】:

    猜你喜欢
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 2016-05-17
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 2016-12-04
    • 2014-12-23
    相关资源
    最近更新 更多