1

I am curious about git add action, so I do some test.

create a index

1. git init
2. mkdir mydir
3. echo "hello" > mydir/hello
4. find .git/objects  ==> nothing 
5. git add .
6. find .git/objects ==> only find one file ,by cat-file,  I am sure it is hello 

do some change

7. rm mydir/hello

get the file back

8. git checkout mydir/hello
9. ls mydir/hello ==> hello is back

My doubt is: when I do 'git add .',there create only one blob, and not create a tree to record the direcoty 'mydir'. So,how could git checkout mydir/hello can find the blob ?

yao
  • 1,993
  • 2
  • 12
  • 10
  • I believe the trees are constructed in `.git/index` alone as that’s often something that will change before the commit is actually made. – poke Jun 27 '12 at 12:08
  • You might find the section in the Pro Git book on the ["Git Internals"](http://git-scm.com/book/en/Git-Internals-Git-Objects) interesting, particularly "Tree Objects". It seems to go over the storage of git fairly well. – simont Jun 27 '12 at 13:47
  • Git Internal just gives an example without directory. It does not explain in detail. – yao Jun 28 '12 at 01:14

1 Answers1

1

The git index does not create tree objects, internally or externally. Directory structures are represented within the filenames of the blobs they contain, until a commit (and its associated tree object) is made.

So in your example the file's name is literally represented as mydir/hello and is associated with the blob you saw.

(Source)

vergenzt
  • 9,669
  • 4
  • 40
  • 47