In this lesson, you looked inside the latest commit of your practice folder and found much more than the one line you changed.
Key Points
git showwith no hash prints your latest commit. Its--statoption adds a count of the changes, like the onegit commitprints, but that’s not everything the commit holds.- Every commit carries a label: the author you set up when you installed Git, the date you made the commit, and the message you typed with it.
- Above the label sits the commit’s hash, the one you met in the last lesson, here in all 40 characters. In a small repository like this one, the first seven, like
ec3c18f, are enough to point at a commit. A bigger project can need a few more to tell its commits apart, so use the short hash Git prints for you.HEADandmainin parentheses mark the commit you’re on, and that’s all you need about them for now. - A commit is a snapshot of every tracked file, in the version you staged. That’s where the shopping cart picture stops working. Last lesson, a clean working tree sounded like an empty cart, but checkout doesn’t empty it. The staging area still holds a copy of every tracked file, matching your last commit, so there’s nothing new to ring up.
git addonly swaps in a newer copy of one, and the next commit takes all of it. - That’s why your third commit kept the old cranberry price. Its snapshot took the copy you added before your cranberry edit.
- Git doesn’t keep a second copy of a file that hasn’t changed. It reuses the one it already has, so snapshots stay small.
- A commit doesn’t store a list of changed lines. When Git shows you changes, it works them out by comparing a commit’s snapshot with the one before it.
- Every commit also records its parent, the hash of the commit right before it.
git log --onelineis Git following those parents back from your latest commit. Your history is a chain that grows by one snapshot with every commit, and your first commit has no parent. - Git calculates the hash from the snapshot, author, date, message and parent together, so every commit gets a name of its own.
The Commands
What git show --stat printed for the latest commit: