IOS development-Summary of configuration and usage of git in xcode

Source: Internet
Author: User

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.

 

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.

 

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.

 

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.

 

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.

 

After the creation is complete, push again. In the displayed dialog box, you can click the push button and click push.

 

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.

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.

 

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.

If a conflict occurs during this process, a dialog box is displayed, showing the conflict points in the two code windows,

The following four buttons can merge and edit conflicting points. If no conflict exists, you can click pull and click pull.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.