Who knows what a pain it is when working on an Xcode project with your team, and resolving conflicts on the
.pbxproj file. Here is a 99% working solution in order to forget this conflicts.
.pbxproj file is a sensible file in a Xcode project, since it maintains information about which files are involved in your project, which ones are compiled or not, on which target, etc.
Most of the time, you are able to solve conflicts by hands, but for someone that doesn't know very well how a
.pbxproj file, he offers himself the right to make a mistake. You can really mess up your project, in a way that Xcode is unable to read your project anymore.
And there exist a really simple workaround for this issue
Here is the not 100% working, but highly recommended solution, for a peace of code.
- Go to the root directory of your git repository, where the
- edit or create the
- add the following line:
*.pbxproj binary merge=union
You're done! Really, I'm not joking, this is that simple.
In the end, the file could look like this, if nothing else was present in that file:
# Telling GIT that Xcode pbxproj remote and local files # should be merged using union of differences *.pbxproj binary merge=union
Let me explain. You're telling GIT that the merge policy of any
pbxproj file is "Union the content of the local and the remote file". This does make sense because when you're adding one or more files to the project and one of your colleague do the same operation, Xcode add the files at the end of the list of the source files list, so this will lead to a conflict when comparing the local and the remote files. Two lines at the same place referencing different files. This command tells GIT to add the added line from the local file, and then below, add the added line from the remote file.
So you added one file, your colleague did that too, and as a result, we have the two files at the end of source files list of the resulting file. And this is what you would have expected.
Attention : It is a 99% working workaround. Indeed, since it is a merge union operation, if two people add the same file, the file will exist and be a duplicate. Xcode may not compile your project after the operation, telling you that duplicate files exist. Go to the Build Phase of the involved target, check in compile sources for duplicates, and remove the bad files. This is the only drawback.