Chapter 3
The Index
In Chapter 2 we introduced the index (held in the .git/index file1) and showed the basic steps for adding files to the Git repository. This chapter discusses the index in more detail.
3.1 The Git Triumvirate: the repo, the index, and the work dir
Figure 3.1 and Figure 3.2 show the relationships between the three main ‘parts’ of Git.
The index contains a list relating hash and mode to file paths.
Use the diff command to illustrate how the index works.
the index ’marks’ all files considered ’tracked’ in the workspace.
files int he workspacece with no entry in the index are ’untracked’
files in the index with hashes different to those in the workspace are ’modified’
the index refers to ’staged’ files. These have hashes (and blobs in the objects store) that are NOT a part of the last commit tree (referened by HEAD).
It is therefore possible to have a single file both ’modified’ (its workspace content differs from that referred to by the index) AND ’staged’ (the ndex refers to an blob that is not the one referenced in the HEAD commit)
1We shall see this, as many things in these early chapters, a partial truth. The index may be split by Git when dealing with large numbers of filename/objects mappings.