I'm toying with the git
plumbing commands to get a better understanding of its inner mechanisms. I'm trying to reproduce a commit without using the git commit
command. Let's create a blob
:
$ git init
$ echo "I'm an apple" > apple.txt
$ git hash-object -w apple.txt
2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14
Now let's add it to the index but with a different filename:
$ git update-index --add --cacheinfo 100644 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14 orange.txt
Here's the output of 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
What is happening here?
apple.txt still exists but is untracked, which seems normal to me as I gave the SHA-1 to the blob
object, which only contains the content of the file.
Let's continue and write the tree:
$ git write-tree
abbb70126eb9e77aaa65efbe0af0330bda48adf7
$ git cat-file -p abbb70126eb9e77aaa65efbe0af0330bda48adf7
100644 blob 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14 orange.txt
$ git cat-file -p 2d1b0d728be34bfd5e0df0c11b01d61c77ccdc14
I'm an apple
Let's finish this operation by creating the commit pointing to this tree:
$ 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
Now, if I run git status
, the output is the same as given above. Why? Also, the commit doesn't seem to have been created:
$ git log
fatal: your current branch 'master' does not have any commits yet
Did I miss something?