iOS version control git summary--yoowei

Source: Internet
Author: User
Tags git commands

One: the preparatory work

1. What is git?

Git is an open source, distributed version Control tool.

Of all the distributed version control tools in the world, Git is the fastest, simplest, and most popular.

Simple comparison of 2.git and SVN

Speed

In many cases, git is much faster than SVN

Structure

SVN is centralized management, and git is distributed management. The biggest difference between distributed and centralized is that, under distributed developers can submit locally, and each developer machine has a database of servers.

Other

SVN is clumsy with branching, and git can easily have an unlimited number of branches

SVN must be networked to work properly, GIT supports local version control work

Older versions of SVN will have one in each directory. Svn,git will only have one. Git in the root directory.

Two. Git's local operation

1. Create a new "local warehouse"

$ git init

2. Configure the Warehouse

"Tell Git who you are.

git config user.name yoowei

"Tell git how to contact you.

git config user.email [email protected]

The above configuration is a one-time configuration, which will be configured in the config file under the. git folder of the managed files to open the view configuration information.

The following is a way to configure the user information in a. gitconfig file in the user directory once and for all. (Finder-Go-personal-apple-.gitconfig)

git config--global user.name yoowei

git config--global user.email [email protected]

# only after the user and the mailbox have been configured, GIT will be able to identify the operation's personnel information, through the hook (hooks) program can set some actions

# For example, when a unit test discovers a problem, automatically sends an email to the person concerned

"View all current configurations

$ git config-l

3. How to learn git commands

> Learning about git instructions and SVN instructions is just the same, but it's not the same way, Git is using the guide to tell us how a certain instruction works

> such as Git help clone this guide is actually a non-editable vim

Q: Exit Guide

Press SPACE: Next page

Control + B: prev

/What you need to search for: you can search

4. Actual development

1> create code and start developing

$ Touch MAIN.C

$ open MAIN.C

2> Adding code to the code base

# View current Code library status

$ git status

# Add a file to the code base

$ git Add main.c

# Commit the changes to the code base

$ git commit-m "added main.c"

Note: If you do not add-M to the commit, you will automatically enter the Vim interface and ask us to enter the modification information.

Press I on the keyboard to start typing

When you are finished, press ESC and then press: WQ

So: If later in the terminal to submit the best in the back plus-m

Note: Add in Git is not the same as add in SVN, only need add once in svn, and git will need to add after each new or modified

# Add all new or modified files under the current folder to the code base at once

$ git Add *

The color before adding

Red is represented in the "workspace"

"Color after adding to staging area

Green code in "staging Area"

Working principle:

If you want to understand how git works, there are several core concepts that you must know

Workspaces (working directory): content other than. Git directory in the Warehouse folder

Repository (Repository):. Git directory for storing record version information

Staging Area (stage)

Branch (Master): the first branch that Git automatically creates

Head pointer: Used to point to the current branch

The principle of git add and git commit

Git add: Add file changes to Staging area

Git commit: Commit all the contents of staging area to the current branch

5. Aliases & Logs

$ git config alias.st status

$ git config alias.ci "commit-m"

Personal advice: Unless special reasons, it is best not to set an alias, or change a machine will not be used

# View all repository logs

$ git log

# View repository logs for specified files

$ git log file name

# Configure a colored log alias

$ git config--global alias.lg "log--color--graph--pretty=format: '%cred%h%creset-%c (yellow)%d%creset%s%cgreen (%CR)% C (bold blue) <%an>%creset '--abbrev-commit '

Note: The version number in Git is a "40-bit" hash value, and the version number in SVN is an incremented integer

Version number, let's shuttle between any version

"has been submitted

Git Reset-hard head^ back to previous version

Where-hard represents a forced reset

Git reset-hard version number (requires only the first 7 bits written)

"Not submitted

git checkout file name fallback to the last committed version

Git Reset-hard head back to the last submitted version, note that there is no caret behind the head ^

>git Reflog View all modifications (all editions)

6. Modification management of individual files

"To see where the files were modified

#git diff file name

If the show green represents the new

If the red indicates that the delete

# Undo changes made to the file

$ git checkout Person.h

Two. Remote operation of Git (for team development)

If multi-person team development, it is best to build a remote warehouse

SVN needs a separate server.

Git doesn't need: files, USB sticks, clouds, GitHub, Oschina ... All can

Ways to build remote warehouses:

Build a git Server yourself: time-consuming and laborious

Hosting projects on GitHub: Public projects free, private project fees, many third-party open source projects

Managed projects on Oschina: Totally free, fast access at home (recommended)

1. Create a new Git remote repository (because of the demo, I also built the remote repository on my computer, there are many git remote warehouse management tools, such as GitHub, in those tools to build a warehouse can be)

"Git init-bare

Note: This repository is for administrative code only and does not participate in development

2. Project Manager initialization project (because of the demo, I also set up the remote warehouse on my Computer)

"2.1 Clone an empty warehouse to the local

git clone/users/apple/desktop/working/company Remote repository

# Personal Information configuration (because to demonstrate multi-person collaboration on a single machine, daily development can be ignored)

$ git config user.name yoowei

$ git config user.email [email protected]

"2.2 Ignores files and folders that do not need to be added to the version controller

. gitignore

Note: Configuring the Ignore file only requires searching on GitHub. Gitignore Copy the code that someone else has written.

Reference URL: Https://github.com/github/gitignore

Configuration. Gitignore must be in the same level directory as. git

Paste the following command into the terminal at once:

Echo-e "# Xcode

#

build/

*.pbxuser

*.mode1v3

*.mode2v3

*.perspectivev3

Xcuserdata

*.xccheckout

*.moved-aside

Deriveddata

*.hmap

*.ipa

*.xcuserstate

# CocoaPods

#

# We recommend against adding the Pods directory to your. Gitignore. However

# Should judge for yourself, the pros and cons is mentioned at:

# Http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control

#

# pods/"> Gitignore

"2.3 After you have generated the. gitignore file, you will also need to add the. gitignore file to version control

git Add. Gitignore

git commit. Gitignore-m "Add. Gitignore"

"2.4 New project (using Xcode)

"Source Conrol->commit commits the code to the local repository

"Source Conrol->push commits the code to the remote repository

A branch is created by default in Git, which is called Origin/master, which is equivalent to the trunk in SVN

Professionals only need to write instructions in the Hooks folder in the GIT repository to complete automated testing (stress, automated, integration, smoke test 、。。。 )

"As with SVN, if the code for the server repository is modified, we will also report an error when we submit the code."

Fetch first = = out of data

Summarize:

The biggest difference between git and svn

"1.git each time you modify the add

"2.git each computer has a warehouse

"3.git is submitted to the local repository before being submitted to the remote repository.

3. New Server Setup

After the company came to the new person will generally give him a new server to build.

1 ". Create a new newcomer server

2. Initializing the Warehouse

Git init--bare

3 "Add a new remote repository

SOURCE control-> master->config->remotes->add-> Add remote

4. Submit the manager's latest code to the new server

5 "Manager assigns new server address to New

4. Branch management-Tag

# View current tab

$ git tag

# tag items in the local code base

Note: This tag is only a local label at the moment. (not related to the server)

$ git tag-a v1.0-m ' Version 1.0 '

# Add tags to the remote code base

$ GIT push Origin v1.0

# with tag, you can quickly switch items to an intermediate state, such as a stable version on a product development line

# Check Out v1.0 tags

$ git Checkout v1.0

# Create a V1.0bugfix branch from checkout status (discover that the 1.0 version that has been submitted has a bug, then we git checkout v1.0 check out version 1.0, and then set a branch to the 1.0 version below)

$ git checkout-b bugfix1.0

# View Remote Branch

$ git branch-r

# Remove Remote Branch

$ git branch-r-D origin/bugfix1.0

1. Development

2. Release

3. Save stable version

4. Continue to develop

5. A bug has occurred in the originally released version

6. Assign an employee to the branch to fix the bug

> Employees download the latest code from the server

"Employees quickly switch to version 1.0 using the git Checkout v1.0 command

"Follow the prompts: Open a new branch to start fixing the code

Git checkout-b 1.0bug_fix

7. Merge the repaired code to the mainline

8. Backup Stable Version

5. Submit the code to GitHub via Xcode and place the warehouse on GitHub

"1. Register a GitHub account

2. Configure SSH keys to seamlessly connect with GitHub as long as you have SSH keys configured

Click on your nickname to visit our homepage

"Click Settings in the home page (setting)

"Click SSH Keys

"Click Generating SSH Keys

"1. Check the local SSH keys

Under "User Directory" Ls-al ~/.ssh

2. If the folder does not exist, you need to manually create a

mkdir. SSH

3. Generate SSH keys based on GitHub tips 2

Execute ssh-keygen-t rsa-c "[email protected]" in the. SSH directory

After the input is finished, press ENTER continuously to know the position of the graphic.

4. After generating public and private keys, enter

Ls-la to see if a successful Id_rsa (private key) id_rsa.pub (public key) is generated

5. Get the public key according to Tip 3

Pbcopy < ~/.ssh/id_rsa.pub

6. Click on setting-ssh key->add ssh key

Add the public key you just acquired.

7. More GitHub 4th step, verify the public key

Verify that the gray dots on the successful web page turn green

8. Open GitHub home page after copying to public key

"Click Warehouse (Repositories)

Click on new to GitHub to create a warehouse interface

9. Download an empty warehouse to a local location via the address provided by GitHub

"Creates a new project into the local warehouse folder

"Using Xcode to submit code to GitHub

Note: When a username password is required, the nickname displayed on GitHub is entered instead of the login account.

6. How do I use/learn a third-party framework?

Excellent third-party frameworks are in github.com

1> Search

2> git clone for full version

$ git clone https://github.com/AFNetworking/AFNetworking.git

3> get the latest version of Git pull

* Enter Clone's local folder

$ git pull

4> See the documentation on GitHub, excellent third-party frameworks have good documentation

5> Write a test program to see the results of the operation

6> for areas of interest, see source code

7> have a problem to http://stackoverflow.com

iOS version control git summary--yoowei

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.