Search code examples
gitgit-svninternalsgit-notes

Why parent is stored in git notes?


The way git store notes:

  • Git only store one note per commit for single namespace. One can have multiple namespace. Default namespace is commit.
  • .git/refs/notes/ contain one hash (say, MainHash_2), which is a tree object. Whenever you create a note the hash get changed.
  • This tree object contain two more hashes. One to another tree structure (the notes tree structure, say NOTES_2) and one to parent tree object(the one in the the .git/refs/notes/ before creating this note, say MainHash_1 )
  • The notes tree structure contains one entry for each note. Each entry have two hash: one to note content and other to specified commit.

As mentioned in third point why the parent is stored? As this parent(its type is same what is mentioned in point two) also contain another tree which contain one entry per note.

Suppose currently you have three notes. MainHash_2 contains a hash to NOTES_2, which contain three entries for each note. MainHash_1 contains a hash to NOTES_1, which contain two entries(for all the remaining notes except the one created now). Why storing these two entries twice and so on??


Solution

  • Simply because notes namespaces are not something special in git, they are just ordinary branches with complete history. You can do

    git checkout notes/commits
    

    and work with your notes as with any other branch, e.g. you can do

    git log notes/commits
    

    to see commit log for your notes. This way you can track all the changes to your notes.

    You said that:

    .git/refs/notes/commits contains one hash (say, MainHash_2), which is a tree object.

    It's not a tree object, it's a commit. Just like in .git/refs/heads/master. You can check it with git cat-file -t <hash>