Git usage Summary-so easy

Source: Internet
Author: User

I. Features of Git

Speed (git is written in C language. Generally, it is submitted to the local device)
Simple Design
Strong support for non-linear development (Thousands of parallel branches) (strong support for nonlinear development)
Fully Distributed (distributed)
Able to handle large projects like the Linux kernel efficiently (speed and data size)

Ii. Git architecture principle

1. snapshots and indexes, instead of incremental, SVN is incremental

2. Almost all operations are local.

3. Three statuses of git files


Committed: files are stored locally safely.
Modified: You modified the file but have not submitted it to your repository.
Staged: a snapshot that has been marked with a modified file to the next version number.


The corresponding process is as follows:
(1), workspace change file
(2), adding snapshot to stage area
(3), commit to Warehouse

4. File status Lifecycle

Iii. Install git and preparations before use

1. Install the SDK directly on the official website.

2. Check the system environment variables and set the identity after installation.

(1) Understand system environment variables
/Etc/gitconfig
. Gitconfig


(2) set the identity
$ Git config -- global user. Name "John Doe"
$ Git config -- global user. Email [email protected]


(3), set the Editor (optional)
$ Git config -- global core. Editor Emacs


(4) set your comparison tool (optional)
$ Git config -- Global merge. Tool vimdiff


(5) Check your configuration (optional)
$ Git config -- list


(6) Help
$ Git help <verb>
$ Git <verb> -- Help

3. Four areas to be understood before development

Blessed (remote) Repository remote Repository
Local repository local repository
Stage area temporary Zone
Work Area

Iv. Git-related commands

Basic commands

1. Initialization

(1) Init enters the working range directory and git init

(2) clone from remote server call git clone git: // github.com/wsj/test.git

2. Added by workspace? To the temporary zone staged, add command

Git add *. Java
Git add wsj.txt

3. submitted from the temporary zone staged to the local repository

Git commit-M "log"

4. view the submission status

Git status

5. Ignore files or directories

Create a new. gitignore file and write the name of the file to be ignored.

6. view the differences between the files in the three regions

$ Git diff -- staged: Workspace vs staged.
$ Git diff -- cached: staged vs local Repo

7. roll back the reset

Three git reset modes
Git reset -- mixed retains the source code of the workspace and rolls back the temporary zone and local repository.
Git reset -- soft retains the source code of the workspace and temporary zone and rolls back the local repository.
Git reset -- hard workspace, temporary zone, and local repository rollback


Git reset -- hard head ^ roll back all content to the previous version, followed by the file name
Git reset -- hard head ~ 3. Roll back to the previous three versions.
Git reset -- hard origin/Master rollback to be consistent with remote Repository

8. Delete the mobile RM mv

Delete but not submitted to the local repository. If you want to retrieve the file, use git checkout filename

Share and update projects

1. Update fetch pull from remote Repository

Git fetch origin is equivalent to obtaining the latest version number from the remote device to the local device, and does not take the initiative to merge
Git pull origin is equivalent to obtaining the latest version number from a remote device and merge to the local device.

For more information, see the blog
Http://blog.csdn.net/hudashi/article/details/7664457

2. Submit to remote Repository

Git push origin master

3. remote warehouse

List remote Repositories
Git remote
Git remote-V display remote address


// Join? Remote Repository
Git remote add Pb git: // github.com/sundyhome/ticgit.git
Git remote rename Pb Paul
Git remote RM Paul
Git remote show origin


Observed ratio log diff

Search for the commit ID corresponding to the tag
Git log -- oneline -- decorate


Branch Management and merge

1. Branch

Git branch branchname: Create a branch

View
Git branch list branches
Git show-branch: List branches and differences
Git diff branch2
Git whatchanged

2. Switch the branch checkout

3. merge branches with merge

Git merge "merge branching to master" head branching


Another approach
Git checkout master
Git pull. branching


4. version number tag

Git tag-A ver1.0-M "My Version 1.0"


// Run the show ver1.0 command to view the version number of the corresponding tag and display the submitted object when tags are added.
Git show ver1.0


// Switch ver1.0
Git checkout ver1.0


To learn how to restore to tag1.0, read the following article.
Http://blog.csdn.net/csfreebird/article/details/8022051


Git usage Summary-so easy

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.