xcode Git pull后Xcode看不到项目中的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11614919/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:00:05  来源:igfitidea点击:

File in the project not seen by Xcode after Git pull

xcodegit

提问by EFC

A partner and I are managing an Xcode project via Git. He recently "localized" the project, which added a directory for German ("de.lproj") to the project with a number of files. After I pulled those changes over to my copy of the project, Xcode now fails to compile complaining that two files in this directory don't exist. These files are present in the filesystem, but displayed as red (missing) in the Xcode sidebar.

我和一个合作伙伴正在通过 Git 管理一个 Xcode 项目。他最近“本地化”了该项目,该项目为项目添加了一个德语目录(“de.lproj”),其中包含许多文件。在我将这些更改拉到我的项目副本后,Xcode 现在无法编译,抱怨此目录中的两个文件不存在。这些文件存在于文件系统中,但在 Xcode 侧栏中显示为红色(缺失)。

Is there a way to force Xcode to rebuild it's internal catalog of files so that it can "rediscover" that these files are, indeed, present?

有没有办法强制 Xcode 重建它的内部文件目录,以便它可以“重新发现”这些文件确实存在?

Note, I've tried a fresh "clone" of this Git project as well, same result.

请注意,我也尝试了这个 Git 项目的新“克隆”,结果相同。

回答by marmor

I found a solution without removing the file from Xcode -

我找到了一个没有从 Xcode 中删除文件的解决方案 -

  1. In the Project Navigator, locate the file (colored red for not being found) and highlight it.
  2. Show the File Inspector
  3. Under Locationchange Absolute Pathto Relative to groupor Relative to project,
  4. Then next to the path, there's a little white icon, click it and choose the file's location.
  1. 在 中Project Navigator,找到该文件(未找到的红色)并突出显示它。
  2. 显示 File Inspector
  3. Location更改Absolute PathRelative to group或 下Relative to project
  4. 然后在路径旁边,有一个白色的小图标,单击它并选择文件的位置。

回答by EFC

This turned out to be a case of absolute vs. group paths memorized in the project.pbxproj file by Xcode. For reasons I do not understand, when my partner localized our project, some files were added to Xcode using absolute paths. When I pulled that version of the project, my copy of Xcode could not find those files because the absolute path did not match my absolute path. Even though the files were in the project and transferred properly by Git, Xcode could not find them.

结果证明这是Xcode在project.pbxproj文件中记忆的绝对路径与组路径的情况。由于我不明白的原因,当我的合作伙伴本地化我们的项目时,使用绝对路径将一些文件添加到 Xcode。当我拉出那个版本的项目时,我的 Xcode 副本找不到这些文件,因为绝对路径与我的绝对路径不匹配。即使文件在项目中并且通过 Git 正确传输,Xcode 也找不到它们。

My solution was to use Xcode to delete these files. Since these were localized files, I actually had to delete the "parent" version of the localized files. I told Xcode to only remove the references to the files. Then I dragged the files from Finder back into Xcode. This time Xcode inserted them as "relative to group" and all was well.

我的解决方案是使用 Xcode 删除这些文件。由于这些是本地化文件,我实际上不得不删除本地化文件的“父”版本。我告诉 Xcode 只删除对文件的引用。然后我将文件从 Finder 拖回 Xcode。这次 Xcode 将它们插入为“相对于组”,一切都很好。

I committed and pushed those changes back to our remote Git repository. My partner was able to pull those to his copy and all worked for him too.

我提交并将这些更改推送回我们的远程 Git 存储库。我的搭档能够将它们拉到他的副本中,并且所有这些都为他工作。

Neither of us understand why the files were inserted as absolute references in the first place, but at least we were able to use this workaround to make the project portable again.

我们都不明白为什么首先将文件作为绝对引用插入,但至少我们能够使用此解决方法使项目再次可移植。

回答by jjpp

Check the project folder path. If any of the folder name in the path contains a 'space' then remove it and open the project again. I had this issue with Xcode 9.

检查项目文件夹路径。如果路径中的任何文件夹名称包含“空格”,则将其删除并再次打开项目。我在 Xcode 9 上遇到了这个问题。