BM: Baca dalam Bahasa Melayu
World 10: Deep Git
Refs, the HEAD file and reftable
You will learn: what a branch really is inside .git, and where Git 3.0 will keep it.
The problem
You make a branch in a huge project. It appears at once. No copying, no waiting. So what is a branch, inside .git?
Pick one answer.
Watch
A ref: A name that points to a commit, like a branch or a tag. is a name for a commit. Branch main is a tiny file in .git/refs/heads. Inside is one commit id.
Try it
.git/HEAD says where you are. Read it. Then detach HEAD, and read it again.
Hint
cat .git/HEAD, then git switch --detach HEAD~1, then cat .git/HEAD again.Predict
You make a new commit on main. What changes in .git/refs/heads/main?
Pick one answer.
Try it
Thousands of tiny ref files get slow. git pack-refs --all puts them in one file: packed-refs: One file in .git that holds many refs together, instead of one small file each.. Pack them, then read it.
Hint
Typegit pack-refs --all, then cat .git/packed-refs.Check
reftable: A newer, faster way to store refs in a few compact tables. Git 3.0 plans it for new repos. is a newer way. Refs live in a few compact tables. Which format fits each fact?
Drag a card into a box. Or tap the card, then tap the box.
Check
Your repo uses reftable. Which command still shows the commit id of main?
Pick one answer.
You did it!
You can now read refs and the HEAD file, and know reftable.
Go deeper (optional)
git show-ref lists every ref with its id. Want reftable today? git init --ref-format=reftable makes a new repo with it. The setting init.defaultRefFormat does it for every new repo. In scripts, ask Git (rev-parse, show-ref). Don’t read .git files.
Bahasa Melayu
Anda buat branch (cabang) dalam projek yang sangat besar. Ia muncul serta-merta. Tiada salinan, tiada tunggu. Jadi, apa sebenarnya branch di dalam .git?
Ref ialah nama untuk satu commit. Branch main ialah fail kecil dalam .git/refs/heads. Di dalamnya ada satu id commit.
.git/HEAD beritahu di mana anda berada. Baca fail itu. Kemudian detach HEAD, dan baca sekali lagi.
cat .git/HEAD, kemudian git switch --detach HEAD~1, kemudian cat .git/HEAD lagi.Anda buat commit baru di main. Apa yang berubah dalam .git/refs/heads/main?
Beribu fail ref kecil jadi lambat. git pack-refs --all masukkan semuanya dalam satu fail: packed-refs. Padatkan, kemudian baca fail itu.
git pack-refs --all, kemudian cat .git/packed-refs.Reftable ialah cara yang lebih baru. Ref disimpan dalam beberapa jadual padat. Format mana sesuai dengan setiap fakta?
Repo anda guna reftable. Arahan mana yang masih tunjuk id commit main?
Kini anda boleh baca ref dan fail HEAD, dan anda kenal reftable.
You finished this before. Practice is always welcome!
Official docs: gitglossary (ref) · git pack-refs · git show-ref · Git 3.0 breaking changes
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?