BM: Baca dalam Bahasa Melayu
World 1: Save Points
Spot the difference
You will learn: how to see exactly what changed, line by line.
The problem
You edited index.html last night. Now you can’t remember what you changed. One line? Ten lines?
Watch
git diff compares your folder with the box. This is a diff. Green + lines are new. Red - lines are gone.
Try it
Tap every line you added.
Tap every added line.
0 of 2 found
Hint
Added lines start with one+. Skip the +++ line: that is just the file name.Predict
You run git add index.html. Then you run git diff again. What shows?
Pick one answer.
Watch
Plain git diff is empty now. To see what is in the box, add --staged. It compares the box with your last commit.
Watch
You can also compare two save points. Give git diff two hashes, older first. It shows what changed between them.
Try it
Put index.html in the box. Then show the diff of the box.
- Empty
- 3 save points
- Add day 2 entry
- Add home page
- Add README
Hint
git add index.html, then git diff --staged.You did it!
You can now spot every change before you save it.
Go deeper (optional)
--cached means the same as --staged. git diff --name-only lists only the names of changed files. Add a file name to see only that file, like git diff index.html.
Bahasa Melayu
Anda ubah index.html semalam. Sekarang anda tak ingat apa yang diubah. Satu baris? Sepuluh baris?
git diff bandingkan folder anda dengan kotak. Inilah diff (beza baris demi baris). Baris hijau + baru. Baris merah - dah hilang.
Tekan setiap baris yang anda tambah.
+. Langkau baris +++: itu cuma nama fail.Anda jalankan git add index.html. Kemudian jalankan git diff sekali lagi. Apa yang keluar?
git diff biasa kini kosong. Untuk tengok isi kotak, tambah --staged. Ia bandingkan kotak dengan commit terakhir (titik simpan terakhir) anda.
Anda juga boleh bandingkan dua titik simpan. Beri git diff dua hash, yang lama dulu. Ia tunjuk apa yang berubah di antaranya.
Masukkan index.html ke dalam kotak. Kemudian tunjuk diff isi kotak.
git add index.html, kemudian git diff --staged.Kini anda boleh nampak setiap perubahan sebelum menyimpannya.
You finished this before. Practice is always welcome!
Official docs: git diff
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?