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 ?
The
gitindex 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/helloand is associated with the blob you saw.(Source)