AI Hints
Git & GitHub · Lesson 106 of 144

Inside Git

Objects and snapshots.

⏱ 2 min read▶ Video at 1:56:37🎓 Free
Watch this lesson in the Git & GitHub courseWatch on YouTube ↗Full Git & GitHub course

You don't need to know how Git works inside to use it. But a quick look makes everything click. Under the hood, Git is a simple database of objects, stored in the dot git folder.

Inside Git
From the video: Inside Git
  • Not required, but helpful
  • Git is a database of objects
  • Stored inside .git

Three kinds of object

There are three main kinds of object. A blob stores the contents of one file. A tree is like a folder listing. It names blobs, and other trees. And a commit points to one tree, the snapshot of the whole project, plus its parent commit, the author, and the message.

  1. Blobthe contents of one file
  2. Treea folder: names to blobs and trees
  3. Commita tree + parent + author + message

Looking at a commit object

Git cat file, dash p, shows any object. For head, our latest commit, we see the tree it points to, its parent commit, the author, the committer, and the message. That's all a commit is. A small text record.

git
git cat-file -p HEAD
tree d6d9f024742731fae1b84b81ab17704be41662c6
parent ef9c9471771c31771bcf60b3dc568df1d1092d1f
author Sam Lee <sam@example.com> 1767605107 +0000
committer Sam Lee <sam@example.com> 1767605107 +0000

Link to about page

Summary

Git stores blobs for files, trees for folders, and commits that point to a tree and a parent. Next, we follow those pointers.

Key takeaways
  • blob = file contents
  • tree = folder
  • commit = tree + parent + message
Next up: Following the Pointers — trees and blobs