BM: Baca dalam Bahasa Melayu
World 10: Deep Git
Revision syntax
You will learn: how to name any commit, or a group of commits, without copying ids.
The problem
You need the commit two steps back. Copying long ids gets old fast. Is there a shorter way?
Watch
A revision: Any way to name a commit: an id, a branch, HEAD~2, v1.0 and more. is any way to name a commit. HEAD~2 means two steps back from HEAD. Each step follows the first parent.
Try it
Count the steps back along main.
Tap the commit that HEAD~3 names.
Hint
The merge has two parents.~ always takes the first one, on main.Predict
HEAD~2 is a merge, so it has two parents. ^2 picks the second one. Which commit is HEAD~2^2?
Pick one answer.
Try it
Visit “Add menu page” with git switch --detach. Name it from HEAD, using ~ and ^.
Hint
Start fromHEAD~2^2. Then go one more step back.Watch
A..B (two dots) lists commits in B that A does not have. Swap the sides, and you see the other side’s extra work.
Try it
A...B (three dots) lists commits on either side, but not both. --left-right marks the sides: < for A, > for B.
Tap the commit that only prices has.
0 of 1 found
Check
Before a merge, you review what prices will bring into main. Which command?
Pick one answer.
You did it!
You can now name any commit without copying its id.
Go deeper (optional)
HEAD^ is the same as HEAD~1. HEAD@{1} is where HEAD was one move ago, from the reflog. v1.0^{} is the commit a tag points to. git rev-parse turns any revision into a full id. git diff main...prices shows what prices changed since it split off.
Bahasa Melayu
Anda perlukan commit (titik simpan) dua langkah ke belakang. Salin id yang panjang memang memenatkan. Ada cara lebih pendek?
Revision ialah apa-apa cara untuk namakan commit. HEAD~2 maksudnya dua langkah ke belakang dari HEAD. Setiap langkah ikut parent pertama.
Kira langkah ke belakang di sepanjang main.
~ sentiasa ambil yang pertama, di main.HEAD~2 ialah merge, jadi ia ada dua parent. ^2 pilih yang kedua. Commit mana ialah HEAD~2^2?
Lawati “Add menu page” dengan git switch --detach. Namakan ia dari HEAD, guna ~ dan ^.
HEAD~2^2. Kemudian satu langkah lagi ke belakang.A..B (dua titik) senaraikan commit dalam B yang tiada dalam A. Tukar sisinya, dan anda nampak kerja tambahan sisi lain.
A...B (tiga titik) senaraikan commit di mana-mana sisi, tapi bukan kedua-duanya. --left-right tandakan sisi: < untuk A, > untuk B.
Sebelum merge, anda semak apa yang prices akan bawa masuk ke main. Arahan mana?
Kini anda boleh namakan mana-mana commit tanpa salin idnya.
You finished this before. Practice is always welcome!
Official docs: gitrevisions · git rev-parse · git log
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?