Git Learning Notes

Source: Internet
Author: User
Tags version control system

Git is a free, open source distributed version control system for agile and efficient processing of any or small or large project. Git is an open source version control software developed by Linus Torvalds to help manage the development of the Linux kernel.

The biggest difference between distributed and centralized is that developers can commit to a local, and each developer copies a full Git repository on the local machine by cloning (git clone).

The schematic diagram of git works as follows:

  

First, describe the GIT-related commands used in Git bash.

1. Git configuration

" Your name "  "Your email"truegit config format.pretty oneline #显示历史记录时 , only one line of comment information is displayed

2. Local Warehouse Management

Build and initialize the local Git repository (CD to the directory where you need to build the repository):

Git init

To add a file in the workspace to staging area (index or stage):

Git add <file name>    #可添加多个文件

To delete a file in staging area:

RM <file name>

Submit the file in staging area to the local repository and add the submission information:

""

Version fallback or undo Modify command:

#在Git中, head represents the current version, the previous version is head^, the last version is head^^, the last 100 versions arehead~ID>   -- Hard head^         <file name>     --<file name>     #撤销工作区的修改    

Branch operations related commands (master Main branch, head pointing to current branch):

Git branch    #查看分支 with *<branch name>    <branch name>     -B <branch name>  #创建并切换到指定分支

git checkout-b <branch name> origin/<branch name> -D <branch name>-D < Branch name> <branch name> #合并指定分支到当前分支 (fast-forward mode) #当Git无法自动合并分支时, must resolve the conflict first, then submit, Merge Complete

(Branch Management principle: Master Branch is stable, only used to release new version, usually operates on other branches, not on master)

Bug Branching operations:

When fixing a bug, create a temporary bug branch to repair, then merge, and then delete. But when the work is not completed, you need to "store" the work site, create a bug branch to fix the bug, delete the bug branch, and finally restore the work site and delete stash content.

git stash #把当前工作现场 "store" git stash list #查看 "store" work site git stash apply  #恢复工作现场git stash drop #删除stash内容git stash Pop #恢复工作现场, and delete stash content

Label (version) Action:

<tag name><tag name>ID>-D <tagname>" Tag Info "  <tag name>--tags #推送全部未推送的本地标签git push origin:refs/tags/<tag name>
    #删除远程标签

Information View command:

Diffdiff HEAD--<file name> #查看指定文件修改的详细信息git log #查看提交日志 (--pretty= Oneline single-line display;--Graph Display Branch chart) git reflog  #查看命令历史

Built-in graphical git:

Gitk

3. Remote Warehouse operation

The protocols that GIT supports to connect to remote repositories are SSH, HTTPS, and so on, and we generally use the SSH protocol.

The address format for the warehouse on GitHub using the SSH protocol is as follows (Take my warehouse Gaohongchen/csharp.git for example):

[Email protected]:gaohongchen/csharp.git or git://github.com/gaohongchen/csharp.git

The remote warehouse of this institution:

1. In the shell, create SSH Key:  ssh-keygen"Your email"     The Id_rsa and id_rsa.pub files that are generated in the. SSH directory must be in the user home directory 2, add the contents of id_rsa.pub to SSH key in GitHub

View Remote Warehouse information (remote warehouse default name is origin):

git remote  #  -V View details (address of remote warehouse)

Associate the local warehouse with the remote warehouse (origin is the Remote warehouse name):

Git remote add origin < remote Warehouse address >RM Origin < remote warehouse address >  #解除关联

To clone a remote repository:

git clone < remote repository address >

Crawl the latest version of the remote repository branch to Local:

Git fetch Origin <branch name>

Crawl the latest version of the remote repository branch to local and merge with the local branch:

Git pull Origin <branch name>

Push the <branch name> branch of the local warehouse (such as master) to the remote repository:

Git push-u origin <branch name>  #第一次推送使用-u parameter

My github address is: https://github.com/GaoHongchen/.

4. Team Work

    1. Push your own changes: Git push origin <branch name>
    2. if (1) fails, because the remote branch is newer than the local, the latest version of the merge branch must be crawled with git pull, and if git pull hints "No tracking information", then the local branch and the remote branch are not connected and must be branch with git-- Set-upstream <branch name> origin/<branch name> Establish connection
    3. If there is a merge conflict, resolve the conflict, and then submit it locally
    4. Execution (1)

Team Collaboration Mode diagram:

  

Reference connection:

Liaoche's git tutorial: http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

Git Learning Notes

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.