Skip to content

Latest commit

 

History

History
147 lines (85 loc) · 3.26 KB

File metadata and controls

147 lines (85 loc) · 3.26 KB

💾 git commit (Create a Snapshot)


🎯 What It Does

Creates a snapshot of your staged changes.


🧪 Command

git commit -m "Add feature"

📸 Visual (Commit Snapshot)

Image

Image

Image

Image

Image

Image

Image


🧠 Mental Model

Commit = snapshot of entire project + metadata


🏗 Internal Architecture (VERY IMPORTANT)

When you run git commit, Git creates a commit object.


🔬 Commit Object Structure

A commit contains:

commit <hash>
Author: Your Name
Date: timestamp

Message: "Add feature"

Points to:
- tree (project snapshot)
- parent commit(s)

📦 Inside .git/objects/

Git stores commits here:

.git/objects/

Each object is stored using a SHA-1 hash.

Example:

a1/b2c3d4e5...

🧩 Object Relationships

Commit → Tree → Blobs

Tree

  • represents folder structure

Blob

  • represents file content

🔗 Parent Relationship

Each commit points to its parent:

A → B → C

👉 This creates history chain


🧠 Why This Matters

Because now you understand:

  • commits are not just messages
  • commits form a graph
  • history is linked via parents

⚠️ Common Mistakes

  • vague messages ("update")
  • committing too much at once
  • not staging properly

✅ Good Practice

git commit -m "Add login validation"

🧠 Memory Trick

Commit = snapshot + message + history link


➡️ Next Step

👉 10-git-log.md