Summary of common problems in configuring and using Git in Xcode

Source: Internet
Author: User
Tags using git

Book on the back of the proposed git in Xcode configuration and use FAQ 4 questions

Question 1, how do I create a code base in Xcode and add and submit code to the code base?

Question 2, how do I submit a push to the remote server code base in Xcode?

Question 3, how do I clone a remote server code library to local in Xcode?

Question 4, how do I use Xcode to get remote code base data and resolve conflict issues?

1. Question 1

There are two ways to create a code base, one to create a new project, another to copy an existing project to a code base, and then to initialize the code base.

If you create a new project, you can choose whether to create it when you save the file, and if you tick "create local git repository for this project", the code base will be created for the project.

Note 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 first line of HelloWorld is the project directory is also the root directory of the code base, the second row of the HelloWorld directory is the source program directory. Our previous directory structure differs from this, and 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 Myrepo is the root of the code base, the second row of HelloWorld is the project directory, such a structure can be a code base can be placed multiple projects, is a one-to-many relationship, and Xcode generated by the code base is the project directory, they are a one-to-one relationship.

If we still use a one-to-many relationship, we don't have to tick the "create local git repository for this project" option when creating the project. This requires copying the existing HelloWorld project to the Myrepo directory and executing the following command in the terminal:

$ CD ~/myrepo

$ git init

Initialized empty Git repository in ~/.git/

After initialization is complete, after adding and submitting the HelloWorld project, execute the following command in the terminal:

$ git Add.

$ git commit-m ' Tony Init '

[Master (root-commit) 98D7E4A] Tony Init

Ten files changed, 643 insertions (+)

Create Mode 100644 Helloworld/helloworld. xcodeproj/project.pbxproj

Create mode 100644 helloworld/helloworld/appdelegate.h

Create mode 100644 HELLOWORLD/HELLOWORLD/APPDELEGATE.M

Create mode 100644 helloworld/helloworld/helloworld-info.plist

Create mode 100644 helloworld/helloworld/helloworld-prefix.pch

Create mode 100644 Helloworld/helloworld/viewcontroller.h

Create mode 100644 HELLOWORLD/HELLOWORLD/VIEWCONTROLLER.M

Create mode 100644 helloworld/helloworld/en.lproj/infoplist.strings

Create mode 100644 Helloworld/helloworld/en.lproj/viewcontroller.xib

Create mode 100644 HELLOWORLD/HELLOWORLD/MAIN.M

Then you can code this project in Xcode . After we have modified and saved the file, we will see an "M" icon behind the file in the navigation panel, which indicates that the file was modified but not submitted.

If you just want to submit the selected file, it can be the right-click menu source Control→commit Selected files ..., where the source control menu is related to code controls. If you want to submit all the modified files, you can menu File→source control→commit .... The dialog box will then pop up.

There are two code windows, a local uncommitted version on the left and a version in the code base on the right, which you can compare to see what has been changed. To add a comment in the input box below, click the Submit button to submit it.

2. Question 2

Local code library submission is pushed to the remote server code base, in Xcode you can file→source control→push by menu ... To push, but if this is the first access, a dialog box will appear with no remote server code base name to push.

We need to create this name on the command line that we created via git remote add HW [email Protected]:myrepo, where HW is the name. In Xcode, you can use the menu Window→organizer, select Repositories→myrepo→remotes, click the "Add Remote" button in the lower left corner, pop up the dialog box, enter Remote_ in the Remote name project. Enter [email Protected]:myrepo] in the Repo,location project and click the Create button when you are done creating this name.

Create and then re-push, if the dialog box pops up, the push button is clickable, click the push button to push.

3. Question 3

This problem is cloned from the server code base to the local, first need to add a remote code library in Xcode, need to go through the menu Window→organizer into the repositories screen, click the "+" button in the lower left corner, select Add Repository, Enter the [email protected],type project Selection Git,name item in the location project will be added automatically, if authentication required to become yellow dot, the configuration connection is not a problem, then click Add button to create the.

If the creation succeeds, it will appear in the list of libraries on the left, select the code base you just created, then select the Clone button below and choose the local save location.

4. Question 4

If the server code has a new version, get Remote code library data to local, you can go through the menu File→source control→pull .... The dialog box will then pop up. Select the Choose button to get the new version.

If there is a conflict in the process, a popup dialog will appear in the two code window to see their conflicting points,

The following 4 buttons allow you to merge the conflict points and edit them. If there is no conflict, pull is clickable, click the Pull button to do it.

------------------------------------------

1. Create a new project with Git
2. Enter the directory
3. Strike according to command:

git config--global user.name "xyling"
git config--global user.email "[Email protected]"
Initializing the Repository
Git init
Add to
git Add. Note that there are spaces
Submit a callout
git commit-m "callouts"
Add Remote branch (two types, switch to yours)
git remote add origin [email protected]:superyou/objective-c.git

-------Remote Connection
Or
Git remote add Origin https://git.oschina.net/superYou/objective-c.git
Upload
Git push-u Origin Master

Summary of common problems in configuring and using Git in Xcode

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.