O'Reilly logo

Version Control with Git by Jon Loeliger

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

A Detailed View of Git’s Object Model and Files

By now, you should have the basic skills to manage files. Nonetheless, keeping track of what file is where—working directory, index, and repository—can be confusing. Let’s follow a series of four pictures to visualize the progress of a single file named file1 as it is edited, staged in the index, and finally committed. Each figure simultaneously shows your working directory, the index, and the object store. For simplicity, let’s stick to just the master branch.

The initial state is shown in Figure 5-1. Here, the working directory contains two files named file1 and file2, with contents foo and bar, respectively.

Initial files and objects

Figure 5-1. Initial files and objects

In addition to file1 and file2 in the working directory, the master branch has a commit that records a tree with exactly the same foo and bar contents for files file1 and file2. Furthermore, the index records SHA1 values, a23bf and 9d3a2 for exactly those same file contents. The working directory, the index, and the object store are all synchronized and in agreement. Nothing is dirty.

Figure 5-2 shows the changes after editing file1 in the working directory so that its contents now consist of quux. Nothing in the index or in the object store has changed, but the working directory is now considered dirty.

Figure 5-2. After editing file1

Some interesting changes take place when you use the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required