深入理解Git (四) -微命令下篇


6 git commit-tree 

这个命令可以用来生成commit对象,commit对象是tree对象的扩展,除了指引tree对象外,还有一些额外的信息,比如此次commit的info,谁commit的,什么时间等。

echo "initial commit" | git commit-tree 4e1ba2916b4b903d2e5a2209cdcca7129a891c2f  

fb1c75a143de21f30004dab829b39f99d225d292

同理,我们看一下:

git cat-file -t fb1c75a143de21f30004dab829b39f99d225d292

commit


git cat-file -p fb1c75a143de21f30004dab829b39f99d225d292

tree 4e1ba2916b4b903d2e5a2209cdcca7129a891c2f
author hongchangfirst <zhc@hongchangfirst.com> 1430193593 +0000
committer hongchangfirst <zhc@hongchangfirst.com> 1430193593 +0000


initial commit

我们看到commit对象自动包含了tree对象的索引,和author的一些信息,另外加上了我们自己写的commit信息。


现在我们就可以git show出来这个commit的信息。

git show commit fb1c75a143de21f30004dab829b39f99d225d292
那么git log呢?

git log

fatal: bad default revision 'HEAD'

这是为什么呢?因为Git会去找.git/HEAD文件,看到里边的内容是ref: refs/heads/master,然后就去找.git/refs/heads/master,非常悲催的发现此文件不存在,那么怎么办呢?


7 ref对象

解决上边的问题很简单,我们只需要更新/refs/heads/master即可。

echo 'fb1c75a143de21f30004dab829b39f99d225d292' > .git/refs/heads/master

现在master就是fb1c75a143de21f30004dab829b39f99d225d292此commit的别名。

我们可以直接

git show master

git log


所以我们清晰的看到了一个链条:

HEAD -> commit对象 -> tree对象 -> blob对象


上边这些微命令如果我们用起来估计要累死了,所以git又聚合了其中的常用命令,比如:

1 git add就是git hash-object和git update-index的聚合,也就是说git add创建blob对象,并且自动将该blob对象添加到cache中。

2 git commit就是write-tree和commit-tree的聚合操作,也就是说git commit会将cache中的对象生成tree对象,并且根据此tree对象生成commit对象。


8 Branch

分支其实是引用,如果想知道分支引用哪个commit对象的话,可以用rev-parse

git rev-parse master

fb1c75a143de21f30004dab829b39f99d225d292


你可以git log一下,看到这个就是位于最顶层的commit对象指针。


原文:http://blog.csdn.net/hongchangfirst/article/details/47445007

作者:hongchangfirst

hongchangfirst的主页:http://blog.csdn.net/hongchangfirst



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值