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
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
.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:
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?
You should check my script xUnique, it is now the best solution to merge Xcode project file before Apple takes action on it.
project.pbxproj
to JSON formatobjects
in JSON and give every UUID an absolute path, and create a new UUID using MD5 hex digest of the path
children
, files
, PBXFileReference
and PBXBuildFile
list and remove all duplicated entries in these lists
sort_pbxproj
method in xUnique.py if you want to know the implementation;PBXFileReference
and PBXBuildFile
Check README file for more details.
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
You can also use Mergepbx manually do it as follows
Install Mergepbx using brew.
brew install mergepbx
Run a command each time you have conflicts in your project file to automatically resolve them.
git mergetool --tool=mergepbx PROJECT.pbxproj
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.