Git一共有3種主要的對(duì)象:
blob:一個(gè)blob對(duì)應(yīng)的就是版本庫(kù)中的一個(gè)文件茄猫,對(duì)象的內(nèi)容就是文件的內(nèi)容。
tree:一個(gè)tree就是一個(gè)文件夾,對(duì)象的內(nèi)容就是它鎖包含的文件夾和文件的指針
commit:對(duì)應(yīng)一次提交
$ git cat-file --batch-check --batch-all-objects
1f7a7a472abf3dd9643fd615f6da379c4acb3e3a blob 10
4441091271cb488f44382e68d48556edfcabaf2d commit 187
5be11cc5fda424a4d7fca1b244052eecd781607e tree 67
767a8378a198a0ae64e1c0bbbc16d437c0eb1f17 blob 15
a7e45836a29172f50a732dde8b13fa36c632797c commit 235
c0db49fbfc9626ee6d439717fdce045d6528ee01 tree 38
ceaa0abfa190c7a89c0a6201935b7057427dabd6 tree 67
e17d94b6cd2820f32b4c454cc90593d798d41430 blob 23
$ git cat-file -p a7e45836a29172f50a732dde8b13fa36c632797c
tree 5be11cc5fda424a4d7fca1b244052eecd781607e
parent 4441091271cb488f44382e68d48556edfcabaf2d
author nina.hao@dmall.com <nina.hao@dmall.com> 1605185871 +0800
committer nina.hao@dmall.com <nina.hao@dmall.com> 1605185871 +0800
commit 2
注意:
blob對(duì)象是在add時(shí)就生成,tree對(duì)象卻是在commit操作時(shí)生成的
..git\refs\tags:靜態(tài)分支貌嫡,不跟隨HEAD移動(dòng)
..git\refs\heads:存放的是指向各分支的指針
..git\HEAD:文件存放的是當(dāng)前工作所在的分支的commit指針
..git\index:文件內(nèi)容就是暫存區(qū)的信息
HEAD也并不總是指向一個(gè)branch,例如:
$ git checkout 4441091271cb488f44382e68d48556edfcabaf2d
Note: switching to '4441091271cb488f44382e68d48556edfcabaf2d'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:
git switch -c <new-branch-name>
Or undo this operation with:
git switch -
Turn off this advice by setting config variable advice.detachedHead to false
HEAD is now at 4441091 commit 1
$ cat ./.git/HEAD
4441091271cb488f44382e68d48556edfcabaf2d
這個(gè)時(shí)候HEAD直接指向一個(gè)commit,Git警告出現(xiàn)detached HEAD現(xiàn)象衅枫。如果這個(gè)時(shí)候創(chuàng)建新的commit嫁艇,由于HEAD沒有指向任何branch朗伶,Git無(wú)法通過移動(dòng)branch來(lái)追蹤新的commit弦撩。因此一旦切換到另一個(gè)branch,在detacheded HEAD下創(chuàng)建的commit很難被找回论皆。
(圖片來(lái)源于網(wǎng)絡(luò)益楼,圖侵刪)
解決方式,新建一個(gè)分支
$ git checkout 4441091271cb488f44382e68d48556edfcabaf2d -b version1
Switched to a new branch 'version1'