Skip to content

Instantly share code, notes, and snippets.

@appleshan
Created April 6, 2018 16:30
Show Gist options
  • Select an option

  • Save appleshan/e958e83bd209ef5ec23fd84f004e31e3 to your computer and use it in GitHub Desktop.

Select an option

Save appleshan/e958e83bd209ef5ec23fd84f004e31e3 to your computer and use it in GitHub Desktop.

Git 的内部结构

Git 真正是一个面向程序员的工具,它的内部数据结构是一个有向无环图,并且,你必须理解它的内部数据结构后,才能掌握它。因为你的很多操作,都其实对应的是这个有向无环图的操作。比如:

  • git commit 就是增加一个结点。
  • git commit –amend 就是改发一个结点。
  • git reset 就是修改 HEAD 指向的结点。

另外,Git 内部包括三个区域:工作区,暂存区和版本库。

  • git add 是将工作区的内容保存到暂存区
  • git checkout 是将暂存区的内容覆盖工作区
  • git commit 是将暂存区的内容保存到版本库
  • git reset 默认情况下是将版本库的内容覆盖工作区
  • git diff 也有三种情况,分别是比较工作区与暂存区,工作区与版本库,暂存区与版本库之间的差别

了解了 Git 的内部结构,对于这些 Git 的命令就更加理解了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment