Xcode Project file git merge conflict

前端 未结 8 1422
萌比男神i
萌比男神i 2021-01-31 03:28

In Xcode, what\'s the best way to avoid Git conflict in the project file? (I am in manual git, not using Xcode interface for git)

I\'ve cloned mapbox-ios-sdk from Github

相关标签:
8条回答
  • 2021-01-31 03:37

    I need to get master code in my branch So, I was taking pull from master and I have changed in my .pbxproj file and master has different configuration.So, It was showing conflict in .pbxproj file. Follow these steps to resolve it

    Open .pbxproj in Finder-> Right click on file Choose Show Package Contents-> Choose .pbxproj file and open it with TextEdit-> It will show conflict lines as below.

    <<<<<<< HEAD"
    // head changes
    ===========
    // Your changes
    >>>>>>>>
    

    You have choose the right one from head Changes and your changes and Delete the rest. Now commit you code

    git add .
    git commit -m"conflict resolved"
    git status // Check you files status
    

    If everything is fine the push you code.

    git push
    
    0 讨论(0)
  • 2021-01-31 03:43

    .pbxproj will change when you add new files to the project. There will be conflicts if two or more collaborators add files at the same time (without getting one another's changes first). We are avoiding this in my project by following these steps before and after adding new files:

    1. Before adding a file, commit your changes, then pull from the master so that you have the latest.If someone has added a file, you now have the latest .pbxproj
    2. Add your file(s).
    3. Immediately commit and push your changes up to the master (hopefully, before another collaborator has added another file).

    It's wimpy, but we don't relish manually resolving .pbxproj conflicts.

    Also, see this Stack Overflow question with excellent responses: How to use Git properly with XCode?

    0 讨论(0)
  • 2021-01-31 03:47

    You should check my script xUnique, it is now the best solution to merge Xcode project file before Apple takes action on it.

    What it does & How it works

    1. convert project.pbxproj to JSON format
    2. Iterate all objects in JSON and give every UUID an absolute path, and create a new UUID using MD5 hex digest of the path
      • All elements in this json object is actually connected as a tree
      • We give a path attribute to every node of the tree using its unique attribute; this path is the absolute path to the root node,
      • Apply MD5 hex digest to the path for the node
    3. Replace all old UUIDs with the MD5 hex digest and also remove unused UUIDs that are not in the current node tree and UUIDs in wrong format
    4. Sort the project file inlcuding children, files, PBXFileReference and PBXBuildFile list and remove all duplicated entries in these lists
      • see sort_pbxproj method in xUnique.py if you want to know the implementation;
      • It's ported from my modified sort-Xcode-project-file, with some differences in ordering PBXFileReference and PBXBuildFile
    5. With different options, you can use xUnique with more flexibility

    Check README file for more details.

    0 讨论(0)
  • 2021-01-31 03:51

    I made an app for fixing things in Xcode project files when these sort of things go wrong. You'd still have to do some manually merging first though, unfortunately. https://itunes.apple.com/us/app/xsaviour/id1449886415?mt=12

    0 讨论(0)
  • 2021-01-31 03:54

    You can also use Mergepbx manually do it as follows

    1. Install Mergepbx using brew.

      brew install mergepbx

    2. Run a command each time you have conflicts in your project file to automatically resolve them.

      git mergetool --tool=mergepbx PROJECT.pbxproj

    0 讨论(0)
  • 2021-01-31 03:56

    A lot of websites simply suggest to use a .gitattributes file with:

    *.pbxproj merge=union

    We're gonna try this approach before trying to use scripts. If we find any issues I'll be sure to update this post. Also if anyone else has comments to this approach please include.

    0 讨论(0)
提交回复
热议问题