BM: Baca dalam Bahasa Melayu
World 3: Parallel Universes
Tidy history with interactive rebase
You will learn: to fix up, reword, drop and reorder your own commits before sharing.
The problem
Your gallery branch works. But look at that history! Can you tidy it before anyone sees it?
Watch
git rebase -i main opens a to-do list of your commits, oldest on top. Change the word in front, and Git replays the list. That’s an interactive rebase: git rebase -i: tidy your own commits before you share them..
Watch
The words: pick keeps a commit. reword gives it a new message. squash: Join a commit into the one before it, and keep both messages. joins it into the one above. fixup: Like squash, but this commit's message is thrown away. joins it and drops its message. drop deletes it.
Try it
Fold “fix typo” into the card above it. Rename “captions” to “Add photo captions”.
Each card is one commit. Pick an action. Drag the grip or use the arrows to reorder.
Top = oldest. Git replays the cards from the top down.
5ab6383Add gallery pagekeep it978a45afix typokeep ite2df039captionskeep it
Hint
fixup for the typo. reword for the captions.Predict
You drop the “debug log” commit. It added debug.txt. What happens to that file?
Pick one answer.
Try it
Now a messier branch. Move “fix typo” right under “Add gallery page” and fix it up. Drop “debug log”.
Each card is one commit. Pick an action. Drag the grip or use the arrows to reorder.
Top = oldest. Git replays the cards from the top down.
5ab6383Add gallery pagekeep itfe5cd49Add photo captionskeep it87ddf3efix typokeep it6961f7bdebug logkeep it
Hint
Move it first. fixup always joins the card just above.Check
Good time to tidy with git rebase -i?
Swipe right for good, left for needs work. Or use the buttons.
Your own branch, before you open a pull request
You did it!
You can now tidy your commits before you share them.
Go deeper (optional)
In a real terminal, git rebase -i main opens this list in your editor. Edit the words, save and close. Got lost? git rebase --abort. Tip: git commit --fixup <commit> marks a fix early. Later, git rebase -i --autosquash main puts it in place for you.
Bahasa Melayu
Branch gallery anda berfungsi. Tapi tengok sejarahnya! Boleh anda kemaskan sebelum orang lain nampak?
git rebase -i main buka senarai tugasan berisi commit anda, yang paling lama di atas. Tukar perkataan di depan, dan Git main semula senarai itu. Itulah rebase interaktif.
Perkataannya: pick simpan commit. reword beri mesej baru. squash gabungkan ke commit atas. fixup gabungkan dan buang mesejnya. drop padam commit itu.
Gabungkan “fix typo” ke dalam kad di atasnya. Tukar nama “captions” jadi “Add photo captions”.
Anda drop commit “debug log”. Commit itu tambah debug.txt. Apa jadi pada fail itu?
Sekarang branch yang lebih bersepah. Alihkan “fix typo” betul-betul di bawah “Add gallery page” dan fixup. Drop “debug log”.
Masa yang sesuai untuk kemas dengan git rebase -i?
Kini anda boleh kemaskan commit sebelum anda kongsi.
You finished this before. Practice is always welcome!
Official docs: git rebase (interactive mode) · git commit --fixup
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?