BM: Baca dalam Bahasa Melayu
World 1: Save Points
Small, focused commits
You will learn: how to split your work into small commits with git add -p.
The problem
You fixed a typo in the title. You also wrote Day 4. Both changes are in index.html. Should they share one commit?
Watch
Good commits are small: one change per commit. Then every message tells the whole truth. And you can undo one change without losing the other.
Watch
git diff shows two separate pieces of change. Each piece is a hunk. Git can save one hunk and leave the other.
Try it
This commit will be “Add day 4 entry”. Pick only the pieces that belong.
Pick the changes that belong in this commit.
index.html
-<title>My Dairy</title>+<title>My Diary</title>
+<p>Day 4: I learned small commits.</p>+<p>test test 123</p>
Try it
Type git add -p. Answer n for the typo fix, and y for Day 4.
- Empty
- 2 save points
- Add home page
- Add README
Hint
-p means patch: Git asks about each hunk. y is yes, n is no.Predict
Now you run git status -s. What do you see for index.html?
Pick one answer.
You did it!
You can now split your work into small, focused commits.
Go deeper (optional)
More answers for git add -p:
qquits.atakes this hunk and the rest of the file.dskips the rest of the file.?shows help.
Real Git has even more, like s to split a big hunk.
Bahasa Melayu
Anda baiki salah taip pada tajuk. Anda juga tulis Day 4. Kedua-duanya dalam index.html. Patutkah ia berkongsi satu commit (titik simpan)?
Commit yang bagus itu kecil: satu perubahan bagi setiap commit. Jadi setiap mesej tepat dengan isinya. Anda juga boleh undur satu perubahan tanpa hilang yang lain.
git diff tunjuk dua cebisan perubahan yang berasingan. Setiap cebisan ialah satu hunk (cebisan perubahan). Git boleh simpan satu hunk dan tinggalkan yang lain.
Commit ini akan jadi “Add day 4 entry”. Pilih hanya cebisan yang sesuai.
Taip git add -p. Jawab n untuk baiki salah taip, dan y untuk Day 4.
-p maksudnya patch: Git tanya tentang setiap hunk. y ya, n tidak.Sekarang anda jalankan git status -s. Apa yang anda nampak untuk index.html?
Kini anda boleh pecahkan kerja anda jadi commit yang kecil dan fokus.
You finished this before. Practice is always welcome!
Official docs: git add (--patch) · git diff
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?