Git Repositories and Commit Snapshots
Repository, working files and commit
A Git repository holds Git’s history and supporting data. In an ordinary local project, you also have a working tree: the files you can open and edit. A commit is a record of a selected project snapshot, with information such as its message, author and links to parent commits (if any). A snapshot describes the state of the recorded files; Git does not need to store a separate full copy of unchanged content for every commit.
Three versions of one file
In our notes lab, checkpoint A records Tea, B records Tea and Rice, and C records Milk and Rice. A new edit adds Bread to the working file without creating another commit. Think of the latest commit as a saved checkpoint and the working file as the current draft. The intermediate selection step, called staging, is explained in Chapter 3.
A: TeaB: Tea / RiceC: Milk / RiceWorking file: Milk / Rice / BreadPreview a real Git command
No installation is required to read this example. To run it, use the supplied Chapter 1 lab setup in a trusted environment with Git installed, then enter its notes directory. The setup creates the three commits and the uncommitted edit above. git show HEAD:notes.txt prints the version of notes.txt recorded in the current commit; HEAD identifies the current commit in this example. It does not overwrite your working file. git show HEAD~1:notes.txt reads the previous checkpoint in this linear history. These are previews; command syntax is taught in later chapters. See lab-fixtures/chapter1-guide.md in the downloadable package for setup and cleanup.
Read the result
The first command prints two lines, Milk and Rice. The second prints Tea and Rice. Neither prints Bread, because that edit was not committed. The commands run one after another, so the terminal output is four lines.
Practice: choose the checkpoint
You need the first version of the note that contained rice but not milk. Which checkpoint should you inspect? Does the working draft containing bread change the old checkpoint? Do not delete or edit the .git metadata to recover files; Git has dedicated commands for inspecting and restoring history. Next, explore how multiple copies of a repository can work independently.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Git Repositories and Commit Snapshots — knowledge check
Check your understanding of the lesson through practical scenarios.
What is the working tree in an ordinary local project?
In the lab, what does `git show HEAD:notes.txt` print?
Which checkpoint contains rice but not milk?
You edit notes.txt again without committing. What happens to the old checkpoint B?
What is true of Git snapshots and storage?