0Pricing
Git Advanced: Monorepo, Submodules & Workflows · Pelajaran

Rebase Interaktif dan Perubahan Komit

Pelajari cara menulis ulang riwayat dengan `git rebase -i` untuk menghasilkan komit yang lebih rapi, serta gunakan `git commit --amend` untuk mengubah komit terakhir.

Rebase Interaktif dan Perubahan Komit adalah pelajaran Git Advanced: Monorepo, Submodules & Workflows gratis di CoddyKit. Ini adalah pelajaran 1 dari 4. Kamu bisa membaca pelajaran lengkapnya di bawah secara gratis — lalu praktikkan langsung di browser dengan editor kode bawaan dan tutor AI 24/7. Ini adalah bagian dari jalur belajar Git Advanced: Monorepo, Submodules & Workflows, dan progresmu tersinkronisasi di web dan aplikasi CoddyKit. Kursus Git Advanced: Monorepo, Submodules & Workflows mencakup 4 pelajaran total.

Bagian dari pelajaran ini belum diterjemahkan dan ditampilkan dalam bahasa Inggris.

Clean Up Your Git History

Git history gets messy — a forgotten file, a typo'd message, ten tiny commits that should be one. Git lets you rewrite history to clean it up.

Amending Your Last Commit

git commit --amend fixes your most recent commit: change the message, add forgotten files, or tweak content. It replaces the last commit with a tidier one.

Amending a Commit Example

Forgot a file right after committing? Stage it, then git commit --amend folds it into the last commit. Here's the flow.

# 1. Make some changes and commit
echo "Initial content" > file1.txt
git add file1.txt
git commit -m "Add file1"

# 2. Realize you forgot file2.txt
echo "More content" > file2.txt
git add file2.txt

# 3. Amend the last commit to include file2.txt
git commit --amend --no-edit

Introducing Interactive Rebase

Need to fix commits further back, not just the last one? Interactive rebase (git rebase -i) is a full editor for a series of commits.

Getting Started with Rebase -i

Start an interactive rebase by naming a commit before your target range. To edit the last three commits, use HEAD~3.

git rebase -i HEAD~3

Rebase Commands: Pick, Reword, Squash

The rebase editor lists commits with commands you can swap: pick keeps it, reword edits the message, squash/fixup merge it up, edit pauses to amend.

Rewording a Commit Message

To change an older commit's message, switch its line from pick to reword in the editor. Git then prompts you for the new message.

# Original rebase editor content:
# pick 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

# Change 'pick' to 'reword' for the first commit:
# reword 8a9b3c4 Add initial feature
# pick d1e2f34 Fix typo in docs

Squashing Commits Together

Got several small commits that belong together? squash merges them into one meaningful commit — change the lines below pick to squash.

# Original commits:
# pick abc1234 Add user registration form
# pick def5678 Add validation for email field
# pick ghi9012 Fix styling on form

# To squash the last two into the first:
# pick abc1234 Add user registration form
# squash def5678 Add validation for email field
# squash ghi9012 Fix styling on form

Editing an Older Commit

The edit command pauses the rebase at a specific commit. Make changes, git add, git commit --amend, then git rebase --continue.

When to Be Careful with Rewriting

Rewriting changes commit IDs — safe for local-only commits. Never rewrite history that's already pushed and shared; it wrecks your collaborators' work.

Quick Check: History Rewriting

You've made a commit with the message "Fix bug". You then realize you forgot to include one small file in that commit. What is the most appropriate Git command to fix this, assuming you haven't pushed the commit yet?

Recap: Cleaner Commits

Recap: git commit --amend fixes the last commit, while git rebase -i rewrites a series — reword, squash, fixup, or edit. Just be careful on shared branches.

Pertanyaan yang Sering Diajukan

Apakah pelajaran “Rebase Interaktif dan Perubahan Komit” gratis?

Ya — teks lengkap “Rebase Interaktif dan Perubahan Komit” gratis dibaca di sini di web. Untuk praktiknya secara interaktif (editor kode bawaan dan tutor AI 24/7) dan buka sisa kursus Git Advanced: Monorepo, Submodules & Workflows, upgrade ke CoddyKit PRO. Kursus Git Advanced: Monorepo, Submodules & Workflows mencakup 4 pelajaran total.

Apa yang akan aku pelajari di “Rebase Interaktif dan Perubahan Komit”?

Pelajari cara menulis ulang riwayat dengan `git rebase -i` untuk menghasilkan komit yang lebih rapi, serta gunakan `git commit --amend` untuk mengubah komit terakhir. Kamu berlatih Git Advanced: Monorepo, Submodules & Workflows dengan kode praktik yang langsung kamu jalankan di browser, dan tutor AI 24/7 menjawab pertanyaanmu saat kamu mengerjakan pelajaran ini.

Apakah aku perlu pengalaman untuk memulai Git Advanced: Monorepo, Submodules & Workflows?

Tidak diperlukan pengalaman sebelumnya. Git Advanced: Monorepo, Submodules & Workflows di CoddyKit dirancang untuk pemula hingga pelajar tingkat lanjut, jadi kamu bisa memulai di sini atau dari awal dan belajar sesuai kecepatan kamu sendiri. Ini adalah pelajaran 1 dari 4.

Berapa lama pelajaran “Rebase Interaktif dan Perubahan Komit” memakan waktu?

Sebagian besar pelajaran CoddyKit memakan waktu sekitar 5–10 menit. Setiap pelajaran ringkas dan interaktif, jadi kamu membuat kemajuan stabil dan melanjutkan dari tempat kamu tinggalkan di web dan aplikasi.

Bisakah aku menulis dan menjalankan kode dalam pelajaran Git Advanced: Monorepo, Submodules & Workflows ini?

Ya. Setiap pelajaran Git Advanced: Monorepo, Submodules & Workflows menyertakan editor kode bawaan, jadi kamu menulis dan menjalankan kode nyata langsung di browser dan mendapatkan umpan balik AI instan — tidak diperlukan penyiapan lokal.

Semua pelajaran dalam kursus ini

  1. Rebase Interaktif dan Perubahan Komit
  2. Menyimpan Sementara dan Memilih Komit
  3. Reflog untuk Pemulihan
  4. Bisect: Menemukan Commit Bermasalah
← Kembali ke Git Advanced: Monorepo, Submodules & Workflows