Git一共有3种主要的对象:
blob:一个blob对应的就是版本库中的一个文件,对象的内容就是文件的内容。
tree:一个tree就是一个文件夹,对象的内容就是它锁包含的文件夹和文件的指针
commit
$ 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对象是在add时就生成,tree对象却是在commit操作时生成的
..git\refs\tags:静态分支,不跟随HEAD移动
..git\refs\heads:存放的是指向各分支的指针
..git\HEAD:文件存放的是当前工作所在的分支的commit指针
..git\index:文件内容就是暂存区的信息
HEAD也并不总是指向一个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
这个时候HEAD直接指向一个commit,Git警告出现detached HEAD现象。如果这个时候创建新的commit,由于HEAD没有指向任何branch,Git无法通过移动branch来追踪新的commit。因此一旦切换到另一个branch,在detacheded HEAD下创建的commit很难被找回。
detached head示意.png
(图片来源于网络,图侵删)
解决方式,新建一个分支
$ git checkout 4441091271cb488f44382e68d48556edfcabaf2d -b version1
Switched to a new branch 'version1'
网友评论