How to use Git with Xcode?

I was an iphone developer for a while, and recently I included git in my workflow. I used the git settings found at http://shanesbrain.net/2008/7/9/using-xcode-with-git for my workflow.

Do these settings show git exclude * .pbxproj from merges? Is there a real reason for this? For example, when I add a file to the project and click on the origin, my developers will not add this file to their xcode project when they pull. Then, if one of them creates a version, this file cannot be included. Should I just let git handle merges for the project file? Can someone explain why or why this file should not be merged and how to properly handle the situation when files are added to the project. Thank.

+83
git objective-c iphone xcode
Apr 10 '10 at 23:11
source share
5 answers

I have been working on full-time iPhone apps since the launch of the SDK; most of the time I worked on teams with several developers.

The truth is that it is more dangerous to refuse to merge this .pbxproj file than it is useful. As you say, when you add a file, if other people do not receive this file, they should also add it to their project - in an application of any size, which sucks, and also takes away a huge profit from source control, since you cannot really return to the full earlier state of the project only through git.

A .pbxproj file is just a list of properties (similar to XML). From experience, just about the only merge conflict that you have ever received is if two people added files at the same time. The solution in 99% of cases of a merge conflict is to preserve both sides of the merge, which for git at least simply involves deleting any โ†’ โ†’, <<<and ==== lines. In fact, it is so common that I created a simple shell script to fix the .pbxproj file in a merge state from git, I run it from the project directory (at the class level):

#!/bin/sh projectfile=`find -d . -name 'project.pbxproj'` projectdir=`echo *.xcodeproj` projectfile="${projectdir}/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 

In case of failure (you ask Xcode to download the project, and it does not load), you simply delete the .pbxproj file, check the wizard from git and re-add your files. But I have never done this for many months with this script, again working full time on iPhone apps with several other developers.

Another option (mentioned in the comments below) that you can try to use instead of the script is to add this line to the .gitattributes file:

 *.pbxproj text -crlf -diff -merge=union 

Then git will always take both sides of the merge for .pbxproject files that have the same effect as script I, only without extra work.

Finally, here is my full .gitignore file showing what I have to ignore, since there are a few things you don't want - in my case, really just the remains of emacs and the entire assembly directory:

 # xcode noise build/* *.pbxuser *.mode1v3 *~ # old skool .svn # osx noise .DS_Store profile 
+124
Apr 11 '10 at 2:00
source share

This works for me in Xcode 4.6 and Git 1.7.5.

Add and commit the .gitattributes file as follows:

 *.pbxproj binary merge=union 

I tested this with another team member and worked great.

Taken from: http://robots.thoughtbot.com/post/33796217972/xcode-and-git-bridging-the-gap

+5
Jul 22 '13 at 18:41
source share

Honestly, existing answers are misleading.

If you never delete or rename files, then using the merge=union strategy, which simply combines the differences in different transactions directly, is a good idea.

However, in the real world, sometimes we sometimes need to delete or rename files. Merging differences without any modifications in these situations would create a lot of problems , and these problems usually lead to the problem "Workspace integrity error - Unable to load project", which makes you even unable to start the project.

The best solution I've got so far:

1) Design the project well and add all the necessary files at the beginning, so you rarely need to modify project.pbxproj .

2) Make your functions tiny. Do not do too many things in the branch.

3) For any reason, if you need to change the file structure and get conflicts in project.pbxproj , use your favorite text editor to solve them manually. Because you make your tasks tiny, conflicts can be easily resolved.

+5
Aug 27 '14 at 7:32
source share

The short answer is that even if you do not include this line in .gitattributes , you cannot easily merge the two modified versions of .pbxproj. It is better for git to treat it as binary.

See here for more details: Git and pbxproj

Update: Although git book still agrees with this answer, I no longer do. I version controls my .pbxproj , like any other non-binary source file.

+2
Apr 10 '10 at 23:21
source share

I created a Python script that can handle merge conflicts in Xcode project files.

If you want to try, you can check it here: https://github.com/simonwagner/mergepbx

You will need to install it as a merge driver, so it is automatically called in case of a merge conflict in the project file (README.md will tell you how to do this).

It should work much better than using merge=union , since mergepbx understands the semantics of your project file and therefore mergepbx conflict correctly.

However, the project is still alpha, do not expect it to understand every project file that is there.

+2
Jan 18 '14 at 22:41
source share



All Articles