Where are tree hashes stored in git?

I follow this tutorial ( https://jwiegley.imtqy.com/git-from-the-bottom-up/1-Repository/3-blobs-are-stored-in-trees.html ) to learn about git architecture.

Team

$ git cat-file commit HEAD

gives me a hash for the tree referenced by HEAD, "0563f77d884e4f79ce95117e2d686d7d6e282887". Now I am trying to find this hash in .git:

$ find .git/ | xargs grep "0563f77"

Why doesn’t it work? This hash is not stored anywhere?

+4
source share
3 answers

A hash does not occur in grep, because the first two digits of this name are the name of the directory:

.git/objects/05/63f77d884e4f79ce95117e2d686d7d6e282887

git .git/objects: https://git-scm.com/book/en/v2/Git-Internals-Git-Objects.

+4

, :

  • Git ( SHA-1) ( , , ) . , SHA-1 -, (commit, blob, tree tag), , , NUL , .

    , , . , README.txt , read-me-too.txt , . , -, ( blob), , , - .

    , hello ( , ), - blob 6\0hello\n ( \0 \n ). ce013625030ba8dba906f756967f9e9ca394464a. ( git hash-object, , SHA-1 : Python Ruby , , C. .)

    ce013625030ba8dba906f756967f9e9ca394464a , hello, . 1 ( , , - Git : Git, . git add , , Git, . , : .)

  • - - - Git.

    , 0563f77d884e4f79ce95117e2d686d7d6e282887, 05 , 63f77 , Git , . Git , .

    , . , . ( Pack .)

  • , , Git. , , :

    commit, $ git rev-parse HEAD. .git/refs/heads/master [ ]

    Git , , commit. Git - . Git , refs/remotes/. , , , "stash" (git stash): , , refs/notes/ () refs/stash .

    , - Git, , . (Git 2.9) , , , packed-refs ( : , ).

- , refs/heads/ 2. - , refs/tags/ 3. SHA-1 . , , , ; .

, , , Git . , git status , on branch master, , Git refs/heads/master, . Git , , commit master , . : , . - , , , .. ( , .)

, , Git, Git.

, , ( git cat-file -p HEAD git cat-file commit HEAD, ): , tree <ugly-sha-1>. , . , , .git/objects/05/... , tree. , ( , zlib, , , -, xdelta, zlib-deflated). - git cat-file : . , , ; git cat-file .

Git, , git cat-file -p :

$ git cat-file -p 'HEAD^{tree}'
[snip]
100644 blob cb2ca2bb2e86aa4a4c3c9b08490c72b04a1778d3    rfuncs.h
040000 tree 05006c6f2e6119fede241cf6ec845291a5be665e    sbuf
[snip more]

, Git blob (cb2ca2b...) Git (05006c6...) Git -, , HEAD .


1 Pigeonhole , , ce013625030ba8dba906f756967f9e9ca394464a , . Git.:-) , -. , , Git, . , 10 -18 1,71 , .

, , , , Git.

2 , master refs/heads. Git , : , x, x/y. , .git/packed-refs, x, x/y, , - . , x x, y. ( , , POSIX .)

3 , Git "", . : refs/tags/, . , , , , , .

Git ( ) Git, .

+3

Try the following:

git log --pretty=format:'%T %s'
+1
source

All Articles