iOS - 将 cocoapods 添加到项目后 git 合并冲突

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26472543/
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-19 10:29:04  来源:igfitidea点击:

iOS - git merge conflicts after adding cocoapods to project

iosgitcocoapodsxcode-projectxcode-workspace

提问by user3344977

I'm working on an app with another partner. He's been working on master, and I started a new branch. On my branch I installed cocoapods. I just tried pulling from master and I'm getting merge conflicts.

我正在与另一个合作伙伴一起开发一个应用程序。他一直在研究 master,而我开始了一个新的分支。在我的分支上,我安装了cocoapods. 我只是尝试从 master 拉取,但遇到了合并冲突。

When I open up Xcode, the workspace file has an error and it says:

当我打开 Xcode 时,工作区文件有一个错误,它说:

"Workspace Integrity - Couldn't load project"

How can I solve this merge conflict?

我该如何解决这个合并冲突?

回答by Suz

When git encounters merge conflicts, it adds lines of text to the conflicting files. They're comments like:

当 git 遇到合并冲突时,它会在冲突文件中添加文本行。他们是这样的评论:

<<<<< HEAD
  ... your code from HEAD...
=========
  ... your code from the merge branch...
>>>>>> my_merged_branch_name

These lines mark where Git needs help. When Xcode runs into one of these lines in a .pbxprojfile, it is unable to open the file and it throws an Workspace Inconsistencyerror.

这些行标记了 Git 需要帮助的地方。当 Xcode 遇到.pbxproj文件中的这些行之一时,它无法打开该文件并引发Workspace Inconsistency错误。

If you look at the messages you got from git, they show which files had the merge conflicts.

如果您查看从 git 获得的消息,它们会显示哪些文件存在合并冲突。

To fix the problem:

要解决问题:

  1. Open each of those file with a simple text editor (I'm old school, so I use vi. Nano will also work. Just make sure you use a code editor and not word processor like TextEdit that will try to change your line endings, etc. )

  2. Resolve the conflicts by removing the comment lines added by git, and deciding which lines of code to keep.

  3. Then tell git that you have resolved the conflicts: git add .

  4. and continue with the merge.

  1. 用一个简单的文本编辑器打开每个文件(我是老派,所以我使用 vi。Nano 也可以。只要确保你使用的是代码编辑器,而不是像 TextEdit 这样的文字处理器,它会试图改变你的行尾,等等。 )

  2. 通过删除 git 添加的注释行并决定保留哪些代码行来解决冲突。

  3. 然后告诉 git 你已经解决了冲突: git add 。

  4. 并继续合并。

Xcode should now be able to open your project.

Xcode 现在应该能够打开您的项目。

回答by Mr H

Here is my 2 Cents.

这是我的 2 美分。

Sometimes even after deleting all of the >>>>and =====still you get the same errors.

有时即使在删除所有内容后>>>>=====您仍然会遇到相同的错误。

  • Clean the project,
  • Run the pod install
  • Build the project
  • 清理项目,
  • 跑过 pod install
  • 构建项目

This should fix the remaining issues.

这应该可以解决剩余的问题。

回答by WDC

Maybe your project.pbxproj is destoryed. if you changed your project.pbxproj,you should check your project.pbxproj carefully by your.xcodeproj -->show Package contents -->project.pbxproj

也许你的 project.pbxproj 被破坏了。如果你改变了你的project.pbxproj,你应该通过你的.xcodeproj -->show Package contents -->project.pbxproj 仔细检查你的project.pbxproj

回答by Sanket Ray

One more way to resolve conflicts, when you cannot access workspace files is to press ?+ ?+ cand should see every single conflict which leads to the error "Workspace Integrity - Couldn't load project".

当您无法访问工作区文件时,解决冲突的另一种方法是按?+ ?+c并且应该看到导致错误的每个冲突"Workspace Integrity - Couldn't load project".

If you are not sure what's wrong with pods or Carthage; you can right-click on pod/Carthage and discard changes. You can later update those pods manually.

如果您不确定 pods 或 Carthage 有什么问题;您可以右键单击 pod/Carthage 和discard changes。您可以稍后手动更新这些 pod。

回答by OhadM

Most chances you have an issue with the project.pbxprojfile which is inside your ProjectName.xcodeproj(right click show package content).

最有可能您的project.pbxproj文件中有问题ProjectName.xcodeproj(右键单击显示包内容)。

You can read up in githubabout a similar issue and there's also a "lint" solution you can try.

您可以在 github 中阅读有关类似问题的信息,也可以尝试使用“lint”解决方案。

I think a faster solution would be moving the HEAD"backwards" in git over each commit until your project file works and once it works, move the HEAD1 commit "forward" and see the changes in project.pbxproj, you will probably see missing closing/opening brackets or perhaps missing semicolon.

我认为一个更快的解决方案将移动HEAD中的git在每个“向后”提交,直到你的项目文件的工作,一旦它的工作原理,将HEAD1提交“前进”,看到的变化project.pbxproj,你可能会看到丢失的关闭/打开括号或也许缺少分号。

Now, that you know what is missing, go to the latest commit and manually fix your project.pbxprojfile using a simple text viewer.

现在,您知道缺少什么,转到最新提交并project.pbxproj使用简单的文本查看器手动修复您的文件。

Good luck.

祝你好运。