Skip to content

November 24, 2010

2

GIT – xcode project file

I have worked on iPhone application full time since last year, Most of that time I spent working on team with multiple developers. And we have been strugling to keep the .pbxproj file in sync across the team. A bit of googling, we ended up in creating a .gitattributes file with the following content

*.pbxproj -crlf -diff -merge

The truth is that it’s way more harmful to disallow merging of that .pbxproj file than it is helpful. As you say, when you add a file unless other people get that file, they have to also add it to their project – in an application of any size, that sucks and it also takes away a huge benefit of source code control in that you cannot really revert to a complete earlier project state just through git.

The .pbxproj file is simply JSON (similar to XML). From experience, just about the ONLY merge conflict you were ever get is if two people have added files at the same time. The solution in 99% of the merge conflict cases is to keep both sides of the merge, which for git at least simply involves removing any >>>>, <<<<, and ==== lines. In fact this is so common that I have created a simple shell script to fix a .pbxproj file in a merge state from git, I run this from within the project directory (at the Classes level):

#!/bin/sh

projectfile=`find -d . -name 'project.pbxproj'`
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"

cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
mv $tempfile $projectfile

Worst case if it fails (you ask XCode to load the project and it fails to load), you simply delete the .pbxproj file, check out the master from git, and re-add your files. But I’ve never had that happen in many months of use with this script, again working full time on iPhone applications with several other developers.

(Courtesy stackoverflow.com)

Read more from GIT
2 Comments Post a comment
  1. Dec 20 2010

    Very useful post. Thank You for taking the time to share your view with us.

  2. Jan 2 2012

    The script also fails when a grouping is done in project files, which I guess occurs frequently in a short time project. Other than that, this is a gift!

Share your thoughts, post a comment.

You must be logged in to post a comment.