如何在 Xcode 中使用 svn 合并冲突(文件 project.pbxproj)?

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

How to merge conflicts (file project.pbxproj) in Xcode use svn?

iphonesvnxcodeconflict

提问by vcLwei

There are two members in our team. We use Xcode's SCM (use SVN) to manger our source code files.
We all add files to our Xcode project. He has committed to SVN server. When I update, Xcode find there has conflicts in project.pbxprojfile. Then I select quit Xcodeand manually merge the conflicts. Then I start to edit my project.pbxproj, merge our changes. Actually I don't know how Xcode manage files, I just add some text that my project.pbxprojfile did't have. When I finish, my project can't open. I guess that because the project.pbxprojfile can't be edit by manual.

我们团队有两个成员。我们使用 Xcode 的 SCM(使用 SVN)来管理我们的源代码文件。
我们都将文件添加到我们的 Xcode 项目中。他已经致力于SVN服务器。当我更新时,Xcode 发现project.pbxproj文件中存在冲突。然后我选择退出Xcode并手动合并冲突。然后我开始编辑我的project.pbxproj,合并我们的更改。实际上我不知道 Xcode 如何管理文件,我只是添加了一些我的project.pbxproj文件没有的文本。完成后,我的项目无法打开。我猜是因为该project.pbxproj文件无法手动编辑。

So, I want to know, when you find this problem, the project.pbxproj file have conflicts, how to solve it?

所以,我想知道,当你发现这个问题时,project.pbxproj文件有冲突,如何解决?

Thank you!

谢谢!

采纳答案by Barry Wark

Unfortunately, there's not much you can do except to make the changes manually in one check out and then check-in the newly "merged" project.

不幸的是,除了在一次签出中手动进行更改然后签入新“合并”的项目之外,您无能为力。

回答by Kendall Helmstetter Gelner

I use git but we see the same issue - if two people add files there's a merge conflict.

我使用 git 但我们看到了同样的问题 - 如果两个人添加文件,则会出现合并冲突。

Usually the editing is very easy though. Simply go into the project.pbxproj file with a text editor, and look for the merge conflict section - usually this is marked by something like :

不过,通常编辑很容易。只需使用文本编辑器进入 project.pbxproj 文件,然后查找合并冲突部分 - 通常用以下内容标记:

>>>>>>>
Stuff 1
======
Stuff 2
<<<<<<<<

In 99% of Xcode project merge conflict cases, you simply want to accept both sides of the merge (because two people added different files) - so you would simply delete the merge markers, in the above case that would end up like:

在 99% 的 Xcode 项目合并冲突情况下,您只想接受合并的双方(因为两个人添加了不同的文件)-因此您只需删除合并标记,在上述情况下,最终会像:

Stuff 1
Stuff 2

Like I said, this works great in MOST cases. If Xcode will not read the project file when you are done, just take the most recent un-merged version and manually add your files again.

就像我说的,这在大多数情况下都很有效。如果完成后 Xcode 不会读取项目文件,只需使用最新的未合并版本并再次手动添加文件。

回答by mmilleruva

This solution is only for git, but you can add a .gitattributesfile to your project then within that file add the following line:

此解决方案仅适用于 git,但您可以将.gitattributes文件添加到项目中,然后在该文件中添加以下行:

*.pbxproj merge=union

*.pbxproj merge=union

This will tell git to keep both sides of the merge which will be what you want the vast majority of the time.

这将告诉 git 保留合并的双方,这在大多数情况下都是您想要的。

回答by Manuel

To manually solve the merge conflicts, check the UUIDof each conflicting item.

要手动解决合并冲突,请检查UUID每个冲突项的 。

Example:

例子:

<<<<<<< HEAD
    6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
    3F01C4B72008E70000889299 /* NewFileA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F01C4B72008E70000889299 /* NewFileA.swift */; };
=======
    6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
    4DF01C4B72008E70000882ED /* NewFileB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF01C4B72008E70000882ED /* NewFileB.swift */; };
>>>>>>> branch_to_merge

Check each UUID:

检查每个 UUID:

  • If it occurs in both versions, remove it in one version: ExistingFile.swift
  • If it does not occur on the comparing branch, keep it: NewFileA.swiftand NewFileB.swift
  • If it is not referenced anywhere else in the file, i.e. you can only find one occurrence in the whole project.pbxprojfile, I would assume it is an artefact and safe to delete it.
  • 如果在两个版本中都出现,请在一个版本中将其删除: ExistingFile.swift
  • 如果它没有出现在比较分支上,保持它:NewFileA.swiftNewFileB.swift
  • 如果文件中的其他任何地方都没有引用它,即您只能在整个project.pbxproj文件中找到一次,我会认为它是人工制品并且可以安全地删除它。

The result would be:

结果将是:

    6B01C4B72008E70000A19171 /* ExistingFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B01C4B62008E70000A19171 /* ExistingFile.swift */; };
    3F01C4B72008E70000889299 /* NewFileA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F01C4B72008E70000889299 /* NewFileA.swift */; };
    4DF01C4B72008E70000882ED /* NewFileB.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4DF01C4B72008E70000882ED /* NewFileB.swift */; };


Note:I don't recommend adding *.pbxproj merge=unionto the .gitattribuesfile to basically ignore merge conflicts because a conflicting merge should alway be checked manually unless there is a sophisticated script doing that for you.

注意:我不建议添加*.pbxproj merge=union.gitattribues文件以基本上忽略合并冲突,因为除非有复杂的脚本为您执行此操作,否则应始终手动检查冲突合并。

回答by G. Shearer

I was looking for a straightforward solution to this problem when I came across this other question/answer:

当我遇到另一个问题/答案时,我正在寻找解决这个问题的直接方法:

https://stackoverflow.com/a/14180388/307217

https://stackoverflow.com/a/14180388/307217

I was completely blown away by how simple this solution is, I was trying to merge in a disparate feature branch which was almost 200 revisions behind the trunk, XCode and Mercurial were not being happy campers about it. I tried manually merging the pbxproj file (which had over 100 conflicts) 8 times before trying this solution.

我完全被这个解决方案的简单震惊了,我试图合并一个不同的功能分支,这个分支在主干后面几乎有 200 个修订版,XCode 和 Mercurial 对此并不满意。在尝试此解决方案之前,我尝试手动合并 pbxproj 文件(有超过 100 个冲突)8 次。

Basically the solution is as such (assuming you use Mercurial, because it's awesome):

基本上解决方案是这样的(假设您使用 Mercurial,因为它很棒):

  1. Attempt your merge in mercurial:

    hg update FEATURE_BRANCH
    hg merge default
    *mercurial gives you a ton of crap about the pbxproj file having merge conflicts*
    
  2. Open Xcode

  3. From the top toolbar, select Xcode->Open Developer Tool->FileMerge
  4. On the left, open your conflicted 'project.pbxproj' file (the one with merge conflict markup in it)
  5. On the right side, open your 'project.pbxproj.orig'
  6. Select File->Save Merge and save over the 'project.pbxproj' file
  7. Then back at the command line:

    hg resolve -m ProjectName.xcodeproj/project.pbxproj
    *merge any other broken files*
    hg commit -m "manually merged with trunk"
    
  8. Eat Cake Because You Are Done
  1. 尝试在 mercurial 中合并:

    hg update FEATURE_BRANCH
    hg merge default
    *mercurial gives you a ton of crap about the pbxproj file having merge conflicts*
    
  2. 打开 Xcode

  3. 从顶部工具栏中,选择 Xcode->Open Developer Tool->FileMerge
  4. 在左侧,打开冲突的“project.pbxproj”文件(其中包含合并冲突标记的文件)
  5. 在右侧,打开您的“project.pbxproj.orig”
  6. 选择 File->Save Merge 并保存“project.pbxproj”文件
  7. 然后回到命令行:

    hg resolve -m ProjectName.xcodeproj/project.pbxproj
    *merge any other broken files*
    hg commit -m "manually merged with trunk"
    
  8. 吃蛋糕,因为你已经完成了

回答by tommys

As stated above the most common wayof handling the conflicts is to

如上所述,处理冲突的最常见方法

  1. accept "everything"
  2. re-import the files into the project
  1. 接受“一切”
  2. 将文件重新导入到项目中

I Wrote a bash-scriptthat takes care of (1) above.

我写了一个bash 脚本来处理上面的 (1)。

Note that this will only solve the most common case of merge conflicts!

请注意,这只会解决最常见的合并冲突情况!

#!/bin/bash
#
#
#
if [ $# -eq 0 ]
 then
    echo "File must be provided as argument, darnit!"
    exit 1
fi

if [ $# -eq 2 ]
 then
    echo "only ONE File must be provided as argument, darnit!"
    exit 1
fi


echo "Will remove lines from file:" 
grep -v "<<<<<"   | grep -v ">>>>>>" | grep -v "====" > out.tmp;mv out.tmp 
echo "Done removing lines from file:" 

回答by realbusyman

Sometimes one or few files could be recreated (for example ManagedObjects) in different branches, so when you'll merge there may be two declarations for one file in one block. In this case you should delete one of the declarations.

有时可能会在不同的分支中重新创建一个或几个文件(例如 ManagedObjects),因此当您合并时,一个块中的一个文件可能会有两个声明。在这种情况下,您应该删除其中一个声明。

回答by qinmu2127

I happened to encounter this tricky problem.

我碰巧遇到了这个棘手的问题。

Instead of manually dealing with these conflicts, you can try this.
Suppose you are on feature branch.

你可以试试这个,而不是手动处理这些冲突。
假设您在功能分支上。

  1. Git checkout master.
  2. Copy content in project.pbxproj
  3. Git checkout to your feature branch, and paste it.(Override the current content in project.pbxproj)
  4. Run

    react-native link
    
  1. Git结帐大师。
  2. 复制内容 project.pbxproj
  3. Git checkout 到您的功能分支,然后粘贴它。(覆盖 中的当前内容project.pbxproj
  4. react-native link
    

回答by Guilherme Vallone

You can open it on VSCODE and fix the conflicting merge there. look for some colored annotations on the IDE or look for <<< >>> in the text search.

您可以在 VSCODE 上打开它并在那里修复冲突的合并。在 IDE 上查找一些彩色注释或在文本搜索中查找 <<< >>>。

回答by Ali Ers?z

So far the best visual merge tool I have used for pbx files is Visual Studio Code's merge tool. I open the pbx file in Code app and fix conflicts then open XCode again.

到目前为止,我用于 pbx 文件的最好的可视化合并工具是 Visual Studio Code 的合并工具。我在 Code 应用程序中打开 pbx 文件并修复冲突,然后再次打开 XCode。