home | list info | list archive | date index | thread index

[OCLUG-Tech] a *proper* definition of the git "index"?

  more a matter of pedantic terminology than anything, but what is the
*proper* description of the git index? i ask since i was teaching a
1-day intro git course at a client site recently, and i explained the
git index the way i normally do (based on my understanding), and a
student took exception, adamantly claiming that he understood it
differently from something he'd read.

  trivially, of course, the git index contains everything you've
staged for the next commit, but more precisely (AIUI, and i hope i
haven't been wrong all this time), the index contains *everything*
that will represent the next commit, not just what you've added,
correct? put another way, at any time, the index contains the state of
the next tree you'll get when you do the next commit.

  what this means is that, even in an unchanged working copy where
nothing's been added, the index represents the *entire* current object
store, not only what's been changed and staged. so that (again, AIUI),
if you make a change and do a "git add", all the new git objects
related to that change are created in the object store, even before
the commit is done. (as i recall, this is why one git book -- whose
name i don't remember -- explained why "git commit" is so fast; all
the work creating objects in the object store has already been done in
advance.)

  this is the way i described it, pointing out that this has an
interesting side effect -- if you create a new file and "git add" it,
its blob is created in the object store; then if you change your mind
and unstage it and delete it, the blob is still in the object store
but nothing will refer to it. not a problem, i said, since git's
garbage collection will eventually figure this out and throw it away.

  the student was adamant that that's not how it worked because that
was so inefficient, but i'm fairly sure that *is* what happens.
thoughts?

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================