1,了解git对象
- git log --pretty=raw --graph
- git cat-file -t "commit hash code"
- git cat-file -t "tree hash code"
- git cat-file -t "parent hash code"
- commit : 本次提交的唯一标识
- tree: 本次提交所对应的目录树
- parent: 本次提交的父提交
- git cat-file -p "commit hash code"
- git cat-file -p "tree hash code"
- f58da9 的类型是tree,所以其内容是列出本次commit对应的目录的内容 welcome.txt
- git cat-file -t "blob hash code"
- git cat-file -p "blob hash code"
- fd3c069 的类型是blob,是commit对应的文件,所以其内容就是文件本身的内容。
- git cat-file -p "parent hash code"
- 07721c 的类型是parent,即本次提交的上一次提交,所以看到的内容是上一次的提交。
2,深入了解 HEAD、master、git对象的关系
先看当前库中所有提交的关系如下图:
- 查看当前branch信息
- git branch
- git log HEAD
- git log master
- git log refs/heads/master
- cat .git/HEAD
- cat .git/refs/heads/master
- git cat-file -t "hash code of .git/refs/heads/master output"
- git cat-file -p "hash code of .git/refs/heads/master output"
- git rev-parse HEAD
- git rev-parse refs/heads/master
- git rev-parse master
呵呵,这里就自己去看图理解啦!
HEAD 是master的一个引用,指向refs/heads/master文件;
master 是最后一次提交;