Wednesday, May 02, 2012

Configure git as XCODE Repository

There is one lecture, Xcode and Source Code Management (October 7, 2011), in the open course of Developing Apps for iOS 2011, by Paul at Stanford University.

Paul demonstrated how to use git as a repository for XCODE source code management. To set up a repository, first, quit XCODE completely, and use Terminal command to set it up.

Set up git Repository

There is one file in XCODE project which saves XCODE UI information. Paul recommended not to check it in. This is a file like xxx.xcuserstate.  To find this filename, change the directory to the project path, and user find command to get the file:

$ cd ~/myprojectpath
$ find . |grep "xcuserstate"

This will find a file name with "xcuserstate". Use the following command to exclude the file:

$ echo xxx.xcuserstate > .gitignore

Then initialize the git and add the source codes (assume the source codes are in the current folder):

$ git init
$ git add .

Use the commit command to seal the change:

$ git commit -m "This is my source code repository with first check-in"

Now the repository is set up. The lecture shows more about how to use the repository to check in changes, comparing changes, and creating branches.

Reset git Repository

In about two days, I have experience fatal error to checking my codes. My case was caused in core data module. I added one to my project, and later on I renamed it. After several files changed, I got fatal error when I tried to check in my codes. The problem is that my renamed data module file cannot be found.

I could uncheck this missing files from commit folder detail on the left panel. However, I cannot ignore or remove this change. Since I have a project with not much changes in repository, I decided to reset my repository.

What I did is to exit XCODE first. From the terminal, local the .git folder and remove it:

$ rm -r .git

This will remove all the files in the repository. There may be a lots of prompt to confirm deleting since files within the folder are read-only. I had to press 'y' to remove all of them.

After removing the repository, I repeated the above steps to get a fresh repository. There may be a way to leave the repository there and create a new one in different repository. I'll update this information when I find the way.