Git是在一个基于内容的文件系统的基础上发展而来的版本控制系统。
所谓基于内容的文件系统具体是指该文件系统只存放文件的内容,文件的名字也是与内容有一定的对应关系,这里文件的名字是通过对内容求SHA-1哈希值的方式命名的。
Git的所有数据都存放在.git目录下,只要有了.git目录及下面的内容,就有了整个工程。
Git的命令分为:plumbing Commands 和 porcelain Commands
管道命令(plumbing Commands):用来处理低层次的任务,诸如:git hash-object、git cat-file之类的
精致命令(porcelain Commands):用来处理用户的任务,就是通常我们所使用的诸如:git config、git add、git commit之类的
空的.git目录结构如下:
[root@localhost temp1]# git init
Initialized empty Git repository in /mnt/temp1/.git/
[root@localhost temp1]# tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── info
│ └── exclude
├── objects
│ ├── info
│ └── pack
└── refs
├── heads
└── tags
9 directories, 13 files
而工作了一段时间的.git目录是这个样子的:
[root@localhost gitLearn]# tree .git
.git
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│ ├── applypatch-msg.sample
│ ├── commit-msg.sample
│ ├── post-update.sample
│ ├── pre-applypatch.sample
│ ├── pre-commit.sample
│ ├── prepare-commit-msg.sample
│ ├── pre-push.sample
│ ├── pre-rebase.sample
│ └── update.sample
├── index
├── info
│ └── exclude
├── logs
│ ├── HEAD
│ └── refs
│ └── heads
│ └── master
├── objects
│ ├── 02
│ │ └── f4378e08c571e665a1cd989b7c634924e2ec7c
│ ├── 08
│ │ └── a0fee9953f6c720dc6ec704e7310700bee62fe
│ ├── 10
│ │ └── dc4b5d3fbf44406860ad7659eea63aeddf0c09
│ ├── 37
│ │ └── 0cc0cc6aba4425ee22cb8dddb1132d06da1031
│ ├── 44
│ │ └── 57cb5d527d7887210e4c444dee322515d89a3c
│ ├── 56
│ │ └── 266d360f3da9f922766101055bd78ffa3724bf
│ ├── 60
│ │ └── 7aa1200b5376230aae4d54cb2c67f20d587b32
│ ├── 64
│ │ └── 24a1d5954cb473169f0395948f0b102743e1dd
│ ├── 87
│ │ └── 042fe12ed70ad4d1df8afb8ffdf5fc28b17a71
│ ├── 9f
│ │ └── 38e428b68e7f7e46ded2ab805f6b8fd8079a92
│ ├── e6
│ │ ├── 31d36fe19ca43588b6a6e884966730a8255c6f
│ │ └── 9de29bb2d1d6434b8b29ae775ad8c2e48c5391
│ ├── info
│ └── pack
└── refs
├── heads
│ └── master
└── tags
23 directories, 30 files
config文件指定了仓库的相关配置
description被Git 的Web程序使用
hooks/用来存放客户端或服务器端的hook脚本
info/存放全局排除的文件类型
HEAD指向当前分支最前端
objects/存放所有版本数据
refs/存放指向提交对象的指针
index存放Git暂存区信息
Git核心是对“键-值”的存储
一些助于理解这一原理的命令:
find .git/objects -type f 查看对应目录下的所有文件(不包含目录)
tree .git 查看目录结构
git hash-object -w <content or file> 存放内容到.git/objects/下
echo "test content' | git hash-object -w --stdin 功能与上相同,--stdin代表echo "test contect"所返回的屏幕结果
git cat-file -p <SHA-1> 查看哈希值对应的文件内容,<SHA-1>至少四位,-p(pretty print object's content)友好显示对象内容的意思
git cat-file -t <SHA-1> 查看哈希值对应的存储对象的类型,blob类型对应于文件,tree类型对应于暂存区的文件组织结构,commit类型对应于版本日志项