您的位置:首页 > 其它

深入理解Git (五) - commit链的形成

2015-09-03 15:01 405 查看
我们新增一个文件比如second,内容为second_information,我们依次执行:

先生成blob对象。

# git hash-object -w second

abcdef

接下来更新cache。

# git update-index --add --cacheinfo abcdef second

接下来生成tree对象。

# git write-tree 

efgh3d

接下来是生成commit链的重点了,我们要加上-p指出它的父亲commit节点是哪个。

# echo "second information" | git commit-tree efgh3d -p prcmit

ger9gd

最后我们更新HEAD的指向

# git update-ref refs/heads/master ger9gd  

其实这条命令相当于,先读出HEAD的内容,比如refs/heads/master,然后更新其内容为新的commit,

大致类似于:

echo "ger9gd" > `cat HEAD`

另外update-ref时,还要更新reflog信息以便进行数据恢复,这个以后再说。好了,我们现在可以git log查看历史commit了。

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

作者:hongchangfirst

hongchangfirst的主页:http://blog.csdn.net/hongchangfirst
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: