Git Introduction and simple structures

  • Git Introduction

  Git (pronounced / gɪt /.) Is a distributed version control system open source, effectively, high-speed processing from very small to very large project version management. Git is Linus Torvalds To help manage Linux kernel development and the development of an open source version control software.
  What is "version control"? Why should I care about it then? Version control is a record of one or several file content changes, for future reference system-specific version of the revision.
  Git is a distributed version control system, then it has no central server, each person's computer is a complete repository, so when the work does not need networking, because they were on their own computers in the repository. Now everyone's computer has a complete repository, how much how individuals collaborate it? For example, to change their own files on the computer A, the others are changed A file on the computer, then, you just need to give each other their own changes pushed between the two, we can see each other's changed.
  The main features are as follows:
  1. Control Version
  2. Distributed
  3. The work process is the code downloaded to the local server, the local development is complete, submitted to the server

  • Comparison of Git and SVN

  1.git is distributed, svn is centralized. (Core)
  2.git each version is stored complete history file for easy recovery, svn diff file is stored, version history can not be restored. (Core)
  3.git most operations can be done offline, svn can not.
  4.git has a more elegant branching and merging implementation.
  5.git has a stronger undo changes and the ability to modify the version history
  6.git faster and more efficient.
  Based on the above difference, git has obvious advantages, especially in that it has a local warehouse.

  • Three states:

  Git has three states, your file may be in one of them: has been submitted (committed), has been modified (modified) and have been staging (staged). Submitted indicates that data was stored in the local security database. Modified expressed modified the file, but not saved to the database. Staging has expressed a modified version of the current file been marked to include a snapshot of the next submission

  • The concept of Git

  1. working directory
  working directory is a version of the project independently extracted the contents of those extracted from the compressed database in the Git repository file on disk for you to use or modify.
  2. The staging area
  is a file, save the file will be submitted to the next list information, usually in the Git repository directory. Sometimes referred to as ` 'Index' ', but the general view is called staging area.
  3.Git repository directory
  is used to save local Git metadata and object database project. This is the most important part of Git, when cloning repository from another computer, where the data is copied

  • Git workflow

  Modify files in the working directory> the temporary file, the snapshot file into the staging area> submit updates, locate the file in the staging area, the snapshot permanently stored in the Git repository directory.
If the Git directory holds the specific version of the file, submitted to belong to the state. If you have been modified and placed in the staging area, already belongs to the temporary status. If since the last time out, but has not been modified into the staging area, it is modified state.

  • Git repositories

  There are two methods to obtain Git repository project. The first is to import all the files in the existing project or directory to Git; the second is to clone an existing Git repository from a server.

 

  • Easy Installation Operation

  Step 1: Install httpd git (here with apache demo)

  yum  -y install  git  httpd 

  Step Two: initialization directory

  git  init 

  Step 3: Create and submit a file

  echo 111 >> index.html
  git add . #提交文件至暂存区域
  git commit -m "v1" #提交文件至仓库

  执行:

  git config --global user.name "Your Name"
  git config --global user.email [email protected]

 

  echo 222 > index.html #再次修改文件
  git add . #进行提交
  git commit -m v2 #v2版本
  cat index.html #查看文件内容
  git log #获取提交信息

 

  git reset --hard 3d0f76d1205fe #执行回滚至v1 后需跟comit ID
  git relog #获取所有的历史提交信息

 

  git  reset  --hard   59ed7a8   #回滚至版本v2

 

  • git不同阶段回滚

  1.工作目录回滚
  echo 33 > index.html #修改文件
  git status #查看文件状态
  git checkout -- index.html #撤销工作目录文件
  cat index.html
  

  2.暂存区域
  echo 33 >index.html
  git add .
  git status
  git reset HEAD index.html
  git checkout -- index.html
  

  3.仓库
  git log
  git relog
  git reset --hard 59ed7a8ca4a

  • git分支:

  1.查看分支
  2.创建分支
  3.切换分支
  4.合并分支


  1)查看分支
  git branch


  2)创建分支
  git branch tian


  3)切换分支
  git checkout tian
  echo 33 > index.html
  git log


  4)合并分支
  git log
  git merge tian #把分支合并到当前分支

 

Guess you like

Origin www.cnblogs.com/t-ym/p/11837606.html