我们新增一个文件比如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