BM: Baca dalam Bahasa Melayu
World 10: Deep Git
Objects and hashes
You will learn: what Git really stores, and how each piece gets its name.
The problem
Your shop has 3 commits. style.css never changed. Does Git store it 3 times?
Pick one answer.
Watch
Git keeps everything as object: One thing Git stores: a blob, a tree, a commit or a tag. Its name is a hash of its content.. git cat-file -p HEAD opens the newest commit. It points to a tree: An object that lists one folder: names that point to blobs (files) and trees (folders). (the files). Its parent is the commit before.
Try it
A blob: An object that holds the content of one file. No name, just the content. is the content of one file. Open the commit, then its tree, then css. Find the blob of css/style.css.
Find the blob that holds css/style.css.
Pick a commit to look inside.
Hint
Click the id on the tree line. Then the id next to css.Check
Three kinds of object. Which one holds each thing?
Drag a card into a box. Or tap the card, then tap the box.
Watch
Each object’s name is a SHA-1: The recipe Git uses today to make a 40-character id from content. hash (commit id): A unique code that names one commit, like a1b2c3d.. It has 40 characters, made from the content. The short id is just the start.
Predict
You copy about.html to about-copy.html and commit. How many new blobs does Git store?
Pick one answer.
Try it
The fourth kind is a tag object: a label with a note. Open v1.0 and see where it points.
Hint
Typegit cat-file -p v1.0.You did it!
You can now open Git’s objects and name all four kinds.
Go deeper (optional)
Annotated tags (git tag -a) are objects. Lightweight tags are only refs. Git compresses each object and keeps it in .git/objects. git cat-file -t prints an object’s type. git cat-file -s prints its size. Git 3.0 plans SHA-256 ids for new repos.
Bahasa Melayu
Kedai anda ada 3 commit (titik simpan). style.css tak pernah berubah. Adakah Git simpan fail itu 3 kali?
Git simpan semuanya sebagai objek (object). git cat-file -p HEAD buka commit terbaru. Ia tunjuk ke satu tree (senarai fail) dan satu parent (commit sebelumnya).
Blob ialah isi satu fail. Buka commit, kemudian tree, kemudian css. Cari blob untuk css/style.css.
Tiga jenis objek. Yang mana simpan setiap benda ini?
Nama setiap objek ialah hash SHA-1. Ia ada 40 aksara, dibuat daripada isinya. Id pendek cuma permulaannya.
Anda salin about.html ke about-copy.html dan commit. Berapa blob baru yang Git simpan?
Jenis keempat ialah objek tag: label dengan nota. Buka v1.0 dan tengok ia tunjuk ke mana.
git cat-file -p v1.0.Kini anda boleh buka objek Git dan namakan keempat-empat jenisnya.
You finished this before. Practice is always welcome!
Official docs: git cat-file · gitglossary (object, blob, tree) · git rev-parse
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?