Use of GIT command line, use of GIT command line

Source: Internet
Author: User
Tags sha1 encryption

Use of GIT command line, use of GIT command line

If you know something wrong, give me some advice.

First, I want to know what GIT is. GIT is an open-source distributed version control tool. Among all the distributed version control tools in the world, GIT is the simplest and most popular, it is also the most commonly used

Compared with other control tools, GIT also has its own characteristics.

For example, GIT differs from SVN in centralized Version Control in the following aspects:

1. In many cases, git is much faster than SVN.

2 SVN is centralized management, git is Distributed Management

3 SVN branch usage is clumsy, and git can easily have unlimited branches

4. SVN must be networked to work. git supports local version control.

5. SVN of the old version will be placed in each directory. git will only have one. git under the root directory.

 

Centralized Version Control


Distributed version control


 

Back to the topic, execute the command line for personal development and use it with GIT developed by the team.

Because it involves the display of hidden files, the display of hidden files can be opened.

Show all
Defaults write com. apple. finder AppleShowAllFiles-bool true
Hide all
Defaults write com. apple. finder AppleShowAllFiles-bool false

Code for personal development drills

1. Enter the desired working directory and initialize a code repository

Lanoudemac-mini-5: ~ lanou $CD / users / lanou / desktop / git drill / personal development
Lanoudemac-mini-5: personal development lanou $git init
Initialized empty git repository in / users / lanou / desktop / git walkthrough / personal development /. Git/

2. you need to configure a user name and email address for the GIT repository. If you do not configure it, your user name will be automatically set as the computer user name, And the mailbox will be the computer user name @ apple.com, because management for users will be involved later, therefore

Set User Name

Lanoudemac-mini-5: personal development lanou $git config user. Name "weiboqy"
Lanoudemac-mini-5: personal development lanou $git config user.email "weiboqy@163.com"
Lanoudemac-mini-5: personal development lanou$

After the settings are completed, no display is displayed. You can check whether your username and email address exist in the/. git/config file in the working directory.

3. Initialization code

Lanoudemac-mini-5: personal development lanou $touch main. M
Lanoudemac-mini-5: personal development lanou $git add main. M

Touch main. m is used to create a main. m file outside the. git directory under the working directory. This file is used for experiment.

Git add main. m is used to add the code of the workspace to the hold Zone

Lanoudemac-mini-5: personal development lanou $touch main. M
Lanoudemac-mini-5: personal development lanou $git add main. M
Lanoudemac-mini-5: personal development lanou $git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
New file: main. M (green)
Lanoudemac-mini-5: personal development lanou $touch main. H
Lanoudemac-mini-5: personal development lanou $git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
New file: main. M (green)
Untracked files:
(use "git add <file>..." to include in what will be committed)
Main. H (red)
Lanoudemac-mini-5: personal development lanou$

4. view the File status in git status

Untracked files: the newly added hosts file or the newly modified hosts file is not added to the temporary workspace.
Changes to be committed (green colors): adds the code in the worker workspace to the hold zone and can be submitted to the code repository.

At this time, you need to understand several core concepts of GIT.

Workspace: work folder (repository folder) content other than the. git directory

Version Library:. git directory, used to store and record version information

Stage)

Master: the first branch automatically created by git

Git add: add changes to files to the hold Zone

Git commit: Submit all content in the hold zone to the current Branch

5. Modify the file

Lanoudemac-mini-5: personal development lanou $open main. M
Lanoudemac-mini-5: personal development lanou$

Open main. m directly. After modification, save git add main. m and add it to the hold zone.

It is troublesome to add a file to the hold zone. git add. You can add all files in the workspace to the hold zone.

6. Alias the git command

Lanoudemac-mini-5: personal development lanou $git config alias.st "status"
Lanoudemac-mini-5: personal development lanou $git config alias.ci "commit-m"
Lanoudemac-mini-5: personal development lanou$

If a long command is entered every time, it will be troublesome, so there is an alias.

Git config alias. alias "original command code"

Compared with this, it will be very convenient.

7. view previous versions

Lanoudemac-mini-5: personal development lanou $git log
commit 503c029c159acb0caa86a178715b1193733b2e34
Author: weiboqy <weiboqy@163.com>
Date:   Sun Mar 27 20:10:34 2016 +0800
Main.m
Lanoudemac-mini-5: personal development lanou $git reflog
503c029 HEAD@{0}: commit (initial): main.m
Lanoudemac-mini-5: personal development lanou$

To view the previous version, you must submit the file to the branch, that is, the git commit command.

You can view previous versions in two ways, as shown in the uplink. When there are many historical versions, we recommend that you use git reflog.

The GITde version number is a 40-bit hash value generated by the sha1 encryption algorithm, so it is very complicated ..

So why is there a history version? For example, I have used the files I have used and there is no good way to restore them, so I only need to roll back to the historical version of a certain period to solve the problem.

8. Historical version rollback

Lanoudemac-mini-5: personal development lanou $git reset - hard head / / back to the current version, but not uploaded to the branch version
//I won't explain it, because the number of versions is not enough
Git reset - hard head ^ / / back to the previous version
Git reset - hard head ^ / / fallback to previous version
Git reset - hard head ~ 100 git reset - the first 7 digits of the hard version number / / the previous 100 versions will be returned 

Code for team development drills

 

Team developers can use folders/GitHub/oschina for code sharing.

1. Folder sharing


If the relationship is shown, weibo serves as the code sharing library.

Therefore, we first created a weibo repository to become a code sharing repository.

LanoudeMac-mini-5: weibo lanou $ cd/Users/lanou/Desktop/GIT walkthrough/team development/code sharing Library/weibo

LanoudeMac-mini-5: weibo lanou $ git init -- bare

Git init -- bare, becomes a code shared library, because it is a shared library of code, so it cannot be a simple gie init

2. The Project Manager clones the content of the code sharing library)

LanoudeMac-mini-5: Project Manager lanou $ git clone/Users/lanou/Desktop/GIT walkthrough/team development/code sharing Library/weibo/

3. The Project Manager initializes the project

Create a ignore Upload File: Create a. gitignore upload file under the. git-level upload directory, and specify the upload file to be ignored in the Upload File.

Search for the. gitignore ranking one on GitHub, or you can enter the content in the. gitignore field.


4. Add. gitignore to the hold zone and submit it to the branch.

Git add.

Git commit-m "comment"

5. Create a project


You cannot create a project under the microblog under the Project Manager directory. Because Git repository is already included, return to the previous directory to create a project.

After use, follow the following order

Modify code-> git commit (submit to local)-> git push (upload to server)

Pull is required before use, so that someone else can modify it and you will not see it.

If someone else needs to join the development, git clone the address of the shared code library

Note the code conflicts and storyboard conflicts.

We recommend that you do not use the storyboard when working with the team, especially when sharing a storyboard, which is especially prone to conflicts, even when moving the storyboard.

Attached a summative Diagram


 

 


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.