The following are four FAQs about Git configuration and usage in Xcode.
Question 1: How do I create a code library in Xcode and add and submit code to the code library?
Question 2: How can I submit the push to the remote server code library in Xcode?
Question 3: How can I clone a remote server code library to a local machine in Xcode?
Question 4: How can I use Xcode to obtain remote code library data and solve conflicts?
1. Question 1
There are two ways to create a code library: one is to create a new project, the other is to copy the existing project to the code library, and then initialize the code library.
If you Create a new project, you can choose whether to Create it when saving the file. If you select "Create local git repository for this project", the code library is created for the project.
650) this. length = 650; "width =" 559 "height =" 120 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F5421G6-0.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F5421G6-0.jpg "alt =" 1 "class =" alignnone size-full wp-image-256 "/>
Note that the directory structure generated by Xcode 4 is as follows:
1 HelloWorld
2 ── HelloWorld
3 │ ──...
4 │ ── ViewController. h
5 │ ── ViewController. m
6 │ ── en. lproj
7 │ ├ ── InfoPlist. strings
8 │ └ ── MainStoryboard. storyboard
9 │ ── main. m
10 ── HelloWorld. xcodeproj
11 │
12 ──. git
The HelloWorld In the first line is the project directory and the root directory of the code library, and the HelloWorld directory in the second line is the directory that stores the source program. Our previous directory structure is different from this. The directory structure is as follows:
1 myrepo
2 ── HelloWorld
3 │ ── HelloWorld
4 │ ──...
5 │ ── ViewController. m
6 │ ── main. m
7 │ ── HelloWorld. xcodeproj
8 ──. git
The first line of myrepo is the root directory of the code library, and the second line of HelloWorld is the project directory. Such a structure can hold multiple projects in a code library, which is a one-to-many relationship, xcode generates code libraries as project directories, which are one-to-one relationships.
If we still adopt a one-to-many relationship, you do not need to select the "Create local git repository for this project" option when creating the project. In this case, you need to copy the existing HelloWorld project to the myrepo directory and execute the following command on the terminal:
$ Cd ~ /Myrepo
$ Git init
Initialized empty Git repository in ~ /. Git/
After initialization, add and submit the HelloWorld project and execute the following command on the terminal:
$ Git add.
$ Git commit-m'tony init'
[Master (root-commit) 98d7e4a] tony init
10 files changed, 643 insertions (+)
Create mode 100644 HelloWorld/HelloWorld. xcodeproj/project. pbxproj
Create mode 100644 HelloWorld/AppDelegate. h
Create mode 100644 HelloWorld/AppDelegate. m
Create mode 100644 HelloWorld/HelloWorld-Info.plist
Create mode 100644 HelloWorld/HelloWorld-Prefix.pch
Create mode 100644 HelloWorld/ViewController. h
Create mode 100644 HelloWorld/ViewController. m
Create mode 100644 HelloWorld/en. lproj/InfoPlist. strings
Create mode 100644 HelloWorld/en. lproj/ViewController. xib
Create mode 100644 HelloWorld/main. m
Then you can code this project in Xcode. After we modify and save the file, we will see an "M" icon behind the file in the navigation Panel. This indicates that the file has been modified but not submitted.
650) this. length = 650; "width =" 381 "height =" 327 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F542CH-2.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F542CH-2.jpg "alt =" 2 "class =" alignnone size-full wp-image-257 "/>
If you only want to submit the Selected file, you can right-click the menu Source Control → Commit Selected Files ..., The Source Control menu is related to code Control. To submit all the modified files, choose File> Source Control> Commit .... A dialog box is displayed.
650) this. length = 650; "width =" 675 "height =" 420 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F5426354-4.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F5426354-4.jpg "alt =" 3 "class =" alignnone size-full wp-image-258 "/>
There are two code windows. The version is not submitted locally on the left, and the version in the code library on the right. here we can compare the modified content. Add a comment in the input box below, and click Submit to submit.
2. Question 2
The local code library is submitted and pushed to the remote server code library. In Xcode, you can choose File> Source Control> Push... Push, but if it is the first access, a dialog box will appear, there is no remote server code library name that can be pushed.
650) this. length = 650; "width =" 567 "height =" 320 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F54225G-6.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F54225G-6.jpg "alt =" 4 "class =" alignnone size-full wp-image-259 "/>
We need to create this name, which is created through $ git remote add hw git@192.168.1.108: myrepo in the command line, where hw is the name. In Xcode, you can select Repositories → myrepo → Remotes from the menu Window → Organizer, click the "Add Remote" button in the lower left corner, and enter remote_repo in the Remote Name Project, enter git@192.168.1.108: myrepo in the Location project, and then click Create to Create the name.
650) this. length = 650; "width =" 707 "height =" 495 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F542A15-8.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F542A15-8.jpg "alt =" 5 "class =" alignnone size-full wp-image-260 "/>
After the creation is complete, Push again. In the displayed dialog box, you can click the Push button and click Push.
650) this. length = 650; "width =" 490 "height =" 283 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F5423491-10.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F5423491-10.jpg "alt =" 6 "class =" alignnone size-full wp-image-261 "/>
3. Question 3
This problem occurs when cloning the code library from the server to the local machine. First, you need to add a remote code library in Xcode. You need to go to the Repositories screen through the menu Window → Organizer, and click the "+" button in the lower left corner, select Add Repository, enter the git@192.168.1.108 in the Location project, select Git for the Type project, and the Name Project will be automatically added. If Authentication required becomes a yellow dot, it indicates that the configuration connection is correct, click Add to create the instance.
650) this. length = 650; "width =" 710 "height =" 379 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F5421V1-12.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F5421V1-12.jpg "alt =" 7 "class =" alignnone size-full wp-image-262 "/>
If the code library is created successfully, it will appear in the code library list on the left. Select the code library you just created, select the Clone button below, and select the local storage location.
650) this. length = 650; "width =" 584 "height =" 470 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F542M05-14.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F542M05-14.jpg "alt =" 8 "class =" alignnone size-full wp-image-263 "/>
4. Question 4
If the server code has a new version and the remote code library data is obtained locally, you can choose File> Source Control> Pull… from the menu .... A dialog box is displayed. Select the Choose button to obtain the new version.
650) this. length = 650; "width =" 492 "height =" 280 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F542MR-16.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F542MR-16.jpg "alt =" 9 "class =" alignnone size-full wp-image-264 "/>
If a conflict occurs during this process, a dialog box is displayed, showing the conflict points in the two code windows,
650) this. length = 650; "width =" 637 "height =" 398 "_ xhe_src =" http://www.bkjia.com/uploads/allimg/131228/0F5424035-18.jpg "src =" http://www.bkjia.com/uploads/allimg/131228/0F5424035-18.jpg "alt =" 10 "class =" alignnone size-full wp-image-265 "/>
The following four buttons can merge and edit conflicting points. If no conflict exists, you can click Pull and click Pull.
This article from the "Guan Dongsheng" blog, please be sure to keep this source http://2009315319.blog.51cto.com/701759/1159343