Core Git 1/8

Git And Commits

Git is a database. The fundamental unit is a commit record: a full snapshot of your project at one moment in time.

Back to Git Concepts overview

Commit Object Anatomy

A commit is not "the changes only." It is a complete photograph of the project state plus pointers and metadata.

Record (commit SHA): 9fab23 snapshot pointer (tree): 73b2a1 parent pointer: ac19f4 metadata: author + time + message example message: feat add webhook payload parser Project snapshot (all tracked files) src/ index.ts utils.ts package.json content hash-addressed and immutable
git show --name-status --oneline HEAD
git cat-file -p HEAD

Commit History

Every commit points to older commit(s), except the first commit which has no parent. A commit can also have two parents (merge commit), which is explained later. Git traverses history by following parent pointers backward.

src/ index.ts utils.ts package.json a9f4c12 src/ index.ts utils.ts package.json b7d1e40 parent src/ index.ts utils.ts package.json c3ab982 parent src/ index.ts utils.ts package.json d8f2a55 parent src/ index.ts utils.ts package.json e1c7b39 parent src/ index.ts utils.ts package.json f4b8c21 feature src/ index.ts utils.ts package.json m9a4f0e parent parent Two parents!
git log --oneline --decorate

Jump To Any Point In History

Because each commit stores a complete snapshot, Git can instantly restore the repository files exactly as they looked at that point in time. Here, `HEAD` and version tags are shown as a preview only; both are explained later in the learning path. The key idea for now is that moving to a saved point in history updates the files to that snapshot immediately.

HEAD a1b2 e4f5 i7j8 m0n1 q3r4 v1.0 v1.1 v1.2 v2.0 v2.1 Project State v1.0 src/ index.ts package.json Instant! COMMAND RUN > git checkout a1b2
git switch --detach v1.0
git checkout a1b2
All Concepts Back To Overview Next DAG + History Graph