Git commit-tree 与 Git commit的区别

'git commit-tree'指令基于一个tree的hash id创建了一个commit对象。

'git commit'则是将暂存区的内容放到仓库。暂存区的通常通常是一个commit对象。

所以,我们可以看到,要将这个commit-tree放入仓库中我们仍需要额外的操作。让我们再来模拟下这个过程。

[wlin@wlin local_version]$ git init
Initialized empty Git repository in /home/wlin/local_version/.git/
[wlin@wlin local_version]$ echo "version 1" > test.txt
[wlin@wlin local_version]$ git hash-object -w test.txt
83baae61804e65cc73a7201a7252750c76066a30
[wlin@wlin local_version]$ git update-index --add --cacheinfo 100644 83baae61804e65cc73a7201a7252750c76066a30 test.txt
[wlin@wlin local_version]$ git write-tree
d8329fc1cc938780ffdd9f94e0d364e0ea74f579
[wlin@wlin local_version]$ echo "first commit" | git commit-tree d8329fc1cc938780ffdd9f94e0d364e0ea74f579
c51498ffa6d93bbe5661249a2e58d43ce0e45924
# 并没有commit生成
[wlin@wlin local_version]$ git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
#   (use "git rm --cached <file>..." to unstage)
#
#	new file:   test.txt
#
# 也没有log生成,显示的错误原因是HEAD没有指定有效的版本
[wlin@wlin local_version]$ git log
fatal: bad default revision 'HEAD'
# 更新master(如果你在其他分支上,则需要指定为其他分支)分支的head的值,指向我们的commit对象
[wlin@wlin local_version]$ git update-ref refs/heads/master b79cf1e3cdb481442f5e11d8bef81466b0f6305f
# 显示我们的commit
[wlin@wlin local_version]$ git log
commit c51498ffa6d93bbe5661249a2e58d43ce0e45924
Author: Cara Wang <wlin@redhat.com>
Date:   Wed Jan 23 16:53:05 2019 +0100

    first commit

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值