BM: Baca dalam Bahasa Melayu
World 10: Deep Git
Plumbing vs porcelain
You will learn: Git's two kinds of commands, and how to save a blob by hand.
The problem
Your script needs the newest commit id. git log prints too much, and its look can change. What should the script use?
Pick one answer.
Watch
Low-level commands are plumbing: Git's low-level commands, like cat-file. Plain, steady output for scripts.: the pipes under the sink. They print plain, steady output. Scripts love them.
Try it
The shiny sink on top is porcelain: Git's friendly everyday commands, like status and commit.: commands for people. Sort each command.
Drag a card into a box. Or tap the card, then tap the box.
Watch
git hash-object prints the id Git would give a file. It matches the blob already in the commit. Same content, same id.
Try it
notes.txt is not in Git yet. Save its content as a blob, with no commit. Then read the blob back.
Hint
Typegit hash-object -w notes.txt. Then git cat-file -p with the id it printed.Predict
Ben has the same notes.txt on his laptop. He runs git hash-object notes.txt. What id does he get?
Pick one answer.
Check
Build the command that prints index.html as the newest commit saved it.
Tap the pieces in the right order.
You did it!
You can now tell plumbing from porcelain and save a blob yourself.
Go deeper (optional)
Porcelain output may change between Git versions. Plumbing output stays steady. Need status in a script? git status --porcelain gives a format that is promised to stay the same. git ls-tree -r --name-only HEAD lists every file in a commit.
Bahasa Melayu
Skrip anda perlukan id commit terbaru. git log cetak terlalu banyak, dan rupanya boleh berubah. Apa yang skrip patut guna?
Arahan peringkat rendah dipanggil plumbing (paip): paip di bawah sinki. Outputnya ringkas dan stabil. Skrip suka arahan ini.
Sinki berkilat di atas pula ialah porcelain (porselin): arahan untuk manusia. Susun setiap arahan.
git hash-object cetak id yang Git akan beri kepada sesuatu fail. Ia sama dengan blob yang dah ada dalam commit. Isi sama, id sama.
notes.txt belum ada dalam Git. Simpan isinya sebagai blob, tanpa commit. Kemudian baca semula blob itu.
git hash-object -w notes.txt. Kemudian git cat-file -p dengan id yang dicetak.Ben ada notes.txt yang sama dalam laptopnya. Dia jalankan git hash-object notes.txt. Id apa yang dia dapat?
Bina arahan yang cetak index.html seperti yang disimpan oleh commit terbaru.
Kini anda boleh bezakan plumbing dan porcelain, dan simpan blob sendiri.
You finished this before. Practice is always welcome!
Official docs: git (high-level and low-level commands) · git hash-object · git cat-file · git ls-tree
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?