The index file, sometimes just referred to as the index, stores information about the current working tree. If for example you add a file, it will first be recorded in the index file so that later, when you do a commit, git will know that the file should be added. This method of recording intermediate status information also comes into play during a merge, where the index file is used for keeping track of resolved and unresolved conflicts.
Besides serving as a "staging area" for changes made between commits, it also serves as a cache for the working tree. This helps performance in trees with a lot of files, since stat information, such as modification time, for each checked out file is placed in the index file so that later operations can compare it against the stat information in the current working tree and thereby ignore files that are unchanged.
The Index File and Everyday Usage
While the index file is an essential part of how the low-level content tracking works, it can in many circumstances be ignored by the user, since the SCM interface will take care of updating the index file. Additionally, understanding how the index file affects the different SCM operations may often be hard for new users. Thus, Cogito chose to hide the index file completely in order to improve usability. However, it proved that understanding the index was much more important than expected, as has been proven by a million too many faulty git commit -a style commits.
ExamplesUsers new to git are often confused by the difference between
$ git diffwhich diffs the working tree against the current index state and
$ git diff HEAD
that diffs the working tree against the state of the last commit.
For more advanced usage patterns the index file can be of significant help. As an example, it lets you record an intermediate state whereby you will be able to diff against this particular state instead of the last commit.