《Pro Git 2》學習筆記_Chapter 10_Git Objects

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類型對應於版本日誌項



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章