Git

Git Introduction

Git简介及其工作原理

Posted by Hao on January 8, 2021

Git 简介

Git是一个分布式版本控制软件,最初由林纳斯·托瓦兹创作,于2005年以GPL发布。最初目的是为更好地管理Linux内核开发而设计。

为何命名为Git

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your way):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • “global information tracker”: you’re in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.

与GitHub、Gitlab & Gitee的联系

GitHub、Gitlab & Gitee均为基于git版本控制系统创建的在线代码托管仓库。

  • Github:最早的开源代码库,拥有超过 2800 万的开发者用户,目前仍然是最火的开源项目托管平台,主要用户为私人账户,现已被Microsoft收购。
  • Gitlab:一款基于 Git 的完全集成的软件开发平台,具有wiki以及在线编辑、issue跟踪功能、CI/CD 等功能。功能相对于GitHub更完善,企业用户较多,并获Google领投。
  • Gitee:是开源中国于2013 年推出的基于Git 的代码托管和协作开发平台,提供本土化的代码托管服务,是中国境内规模最大的代码托管平台,解决访问GitHub或Gitlab时访问过慢的问题。

Git的三个工作区

GitWorkplace

  • Workspace:工作区
  • Index / Stage:暂存区
  • Repository:仓库区(或本地仓库)
  • Remote:远程仓库

Git文件的四种状态

git库所在的文件夹中的文件大致有4种状态 GitFileSystem

  • Untracked: 未跟踪, 此文件在文件夹中, 但并没有加入到git库, 不参与版本控制,通过git add 状态变为Staged。
  • Unmodify: 文件已经入库, 未修改, 即版本库中的文件快照内容与文件夹中完全一致。这种类型的文件有两种去处, 如果它被修改, 而变为Modified。如果使用git rm移出版本库, 则成为Untracked文件。
  • Modified: 文件已修改, 仅仅是修改, 并没有进行其他的操作。这个文件也有两个去处, 通过git add可进入暂存staged状态, 使用git checkout 则丢弃修改过, 返回到unmodify状态, 这个git checkout即从库中取出文件, 覆盖当前修改。
  • Staged: 暂存状态,执行git commit则将修改同步到库中, 这时库中的文件和本地文件又变为一致, 文件为Unmodify状态;执行git reset HEAD filename取消暂存, 文件状态为Modified。