我正在玩弄git
管道命令以更好地了解其内部机制。我正在尝试在不使用该git commit
命令的情况下重现提交。让我们创建一个blob
:
$ git init
$ echo "I'm an apple" > apple.txt
$ git hash-object -w apple.txt
2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14
现在让我们将它添加到索引中,但使用不同的文件名:
$ git update-index --add --cacheinfo 100644 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14 orange.txt
这是输出git status
:
$ git status
On branch master
Initial commit
Changes to be committed:
(use "git rm --cached <file>..." to unstage)
new file: orange.txt
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: orange.txt
Untracked files:
(use "git add <file>..." to include in what will be committed)
apple.txt
这里发生了什么?
apple.txt仍然存在但未被跟踪,这对我来说似乎很正常,因为我将 SHA-1 提供给了blob
仅包含文件内容的对象。
让我们继续写树:
$ git write-tree
abbb70126eb9e77aaa65efbe0af0330bda48adf7
$ git cat-file -p abbb70126eb9e77aaa65efbe0af0330bda48adf7
100644 blob 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14 orange.txt
$ git cat-file -p 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14
I'm an apple
让我们通过创建指向这棵树的提交来完成这个操作:
$ echo "Add fruit" | git commit-tree abbb70126eb9e77aaa65efbe0af0330bda48adf7
57234c35c0d58713d2b4f57b695043e5331afe58
$ git cat-file -p a4386cb82e1f6d1755e47ace1f378df35df31967
tree abbb70126eb9e77aaa65efbe0af0330bda48adf7
author Gregoire Borel <gregoire.borel@nxxx.xx> 1527001408 +0200
committer Gregoire Borel <gregoire.borel@xxx.xx> 1527001408 +0200
Add fruit
现在,如果我运行git status
,输出与上面给出的相同。为什么?此外,似乎还没有创建提交:
$ git log
fatal: your current branch 'master' does not have any commits yet
我错过了什么?