BM: Baca dalam Bahasa Melayu
World 2: Undo Magic
Throw away a change
You will learn: how to throw away changes you don't want.
The problem
You edited index.html and broke it. Ctrl+Z can’t go back that far. Now what?
Watch
git restore index.html puts the file back to its last saved version. This is called restore: Put a file back to a saved version..
Watch
⚠️ Danger: restore throws your changes away for good. Git never saved them, so there is no undo. Look first with git diff.
Try it
Throw away the broken index.html. Keep your style.css change.
- Empty
- 3 save points
- Add style
- Add day 1 page
- Add README
Hint
Typegit restore index.html, then press Enter.Predict
Now you run git restore style.css. What happens to your teal heading?
Pick one answer.
Check
Deleted a saved file by mistake? git restore brings it back. It is in a commit, so Git still has it.
You did it!
You can now throw away changes you don’t want. Carefully!
Go deeper (optional)
git restore copies from the box. If you staged the file, you get the staged version. git restore . restores every tracked file. Old guides use git checkout -- index.html. It does the same job.
Bahasa Melayu
Anda ubah index.html, dan ia jadi rosak. Ctrl+Z tak boleh undur sejauh itu. Jadi, macam mana?
git restore index.html kembalikan fail itu kepada versi terakhir yang disimpan. Ini dipanggil restore (pulihkan).
⚠️ Bahaya: restore buang perubahan anda terus. Git tak pernah simpan perubahan itu, jadi tiada undo. Semak dulu dengan git diff.
Buang index.html yang rosak. Kekalkan perubahan style.css anda.
git restore index.html, kemudian tekan Enter.Sekarang anda jalankan git restore style.css. Apa jadi pada tajuk warna teal anda?
Terpadam fail yang dah disimpan? git restore bawa ia balik. Fail itu ada dalam commit (titik simpan), jadi Git masih ada salinannya.
Kini anda boleh buang perubahan yang anda tak mahu. Dengan berhati-hati!
You finished this before. Practice is always welcome!
Official docs: git restore · git diff · git checkout
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?