At first initialize a repo containing a file named rose
$: echo sweet > rose
$: git init
$: git add .
$: find .git/objects/ -type f
.git/objects/aa/823728ea7d592acc69b36875a482cdf3fd5c8d
$: git commit -m "rose"
$: find .git/objects/ -type f -printf "%h%f %s\n"
.git/objects/05b217bb859794d08bb9e4f7f04cbda4b207fbe9 49
.git/objects/aa823728ea7d592acc69b36875a482cdf3fd5c8d 21
.git/objects/665d02ccbacdde1c0f2eecde01fbf47144ddd492 124
Then I want to sha the blob and see how to generate tree-object’s id
echo -e "tree 21\0100644 rose\0aa823728ea7d592acc69b36875a482cdf3fd5c8d"|sha1sum
What it print is not 05b217bb859794d08bb9e4f7f04cbda4b207fbe9
Where am i wrong?
echoinserts a newline by default, unless you specify the-n(omit newline) flag.Also, the blob ID is not stored in ASCII format, but rather as binary value. This results in a object size of 32 (not 21).
The following command will give you the correct output: