How does Git know which Index blob to add to a tree?
Posted
by drozzy
on Stack Overflow
See other posts from Stack Overflow
or by drozzy
Published on 2010-04-27T14:23:44Z
Indexed on
2010/04/27
16:13 UTC
Read the original article
Hit count: 183
git
In Pro Git Ch9 the author says:
Git normally creates a tree by taking the state of your staging area or index and writing a tree object from it.
My question is how does git know which of two consequitive index entries to create the Tree object from?
For example:
$ echo 'First change' > one.txt
$ git add one.txt
$ find .git/objects -type f
.git/objects/1f/755a7fffe4 //first index entry
$ echo 'Second change' > one.txt
$ git add one.txt
$ find .git/objects -type f
.git/objects/2d/234asdf2 //second index entry
$ git commit -a -m "Initial commit"
$ git cat-file master^{tree}
100644 blob 2d234asdf2 one.txt //How did it know not to take 1f755??
Does it just look at the blob timestamps? Also - what happens to the first blob created - no one is referencing it. Does it just get destroyed or forgotten?
© Stack Overflow or respective owner