How to merge conflicts (file project.pbxproj) in X

2019-01-06 09:51发布

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.pbxproj file. Then I select quit Xcode and 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.pbxproj file did't have. When I finish, my project can't open. I guess that because the project.pbxproj file can't be edit by manual.

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

Thank you!

10条回答
SAY GOODBYE
2楼-- · 2019-01-06 10:18

I founded a tool "xUnique" https://github.com/truebit/xUnique, it works!

查看更多
趁早两清
3楼-- · 2019-01-06 10:19

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

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.

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

  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
查看更多
姐就是有狂的资本
4楼-- · 2019-01-06 10:19

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.

查看更多
霸刀☆藐视天下
5楼-- · 2019-01-06 10:22

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

*.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.

查看更多
男人必须洒脱
6楼-- · 2019-01-06 10:28

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
    
查看更多
女痞
7楼-- · 2019-01-06 10:29

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

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 :

>>>>>>>
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:

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.

查看更多
登录 后发表回答