Menyelamatkan Pekerjaan dengan Reflog dan Stash
Kuasai jaring pengaman Git: gunakan reflog untuk memulihkan keadaan setelah reset dan rebase yang keliru, serta gunakan stash untuk menyisihkan dan memulihkan pekerjaan yang sedang berlangsung dengan aman selama pemulihan.
Menyelamatkan Pekerjaan dengan Reflog dan Stash adalah pelajaran Git Advanced: Monorepo, Submodules & Workflows gratis di CoddyKit. Ini adalah pelajaran 4 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.
Git Rarely Loses Data
It feels like a bad reset or rebase destroys work, but Git almost never truly loses commits. They become unreachable, not deleted, and remain recoverable for weeks.
The reflog is your map back to them.
What the Reflog Records
The reflog logs every move of HEAD and branch tips: commits, checkouts, resets, rebases, merges. It is local and not shared, a private diary of where your refs have been.
git reflog
# a1b2c3d HEAD@{0}: reset: moving to HEAD~3
# 9f8e7d6 HEAD@{1}: commit: add featureRecovering After a Bad Reset
Ran git reset --hard and lost commits? Find the pre-reset SHA in the reflog and reset back to it.
git reflog
git reset --hard HEAD@{1}Recovering After a Bad Rebase
A rebase rewrites commits. If it went wrong, the reflog still holds the pre-rebase tip. Point your branch back at it.
git reflog
git reset --hard HEAD@{5} # the entry just before 'rebase'Restoring a Single Lost Commit
You do not always want to reset the whole branch. To resurrect just one commit, cherry-pick its SHA from the reflog.
git cherry-pick 9f8e7d6The Stash as a Safety Net
Before risky recovery operations, save uncommitted work with git stash. It tucks changes away cleanly so you can experiment without losing them.
git stash push -m 'wip before recovery'Inspecting and Restoring Stashes
List stashes and bring one back. apply keeps it in the list; pop restores and removes it.
git stash list
git stash show -p stash@{0}
git stash pop stash@{0}Recovering Dropped Stashes
Dropped a stash by mistake? Stashes are commits too. Find the dangling commit and re-apply it.
git fsck --no-reflogs | grep commit
git stash apply <dangling-sha>Finding Orphans with fsck
When even the reflog does not show it, git fsck --lost-found hunts for dangling commits and blobs, the last-resort recovery tool.
git fsck --lost-foundThe Garbage Collection Clock
Unreachable objects survive until garbage collection prunes them, by default after about 30 days for reflog entries. Recover promptly; do not let weeks pass before you go looking.
The Reflog Is Local Only
Remember: the reflog lives only in your clone. A teammate's reflog will not show your moves, and a fresh clone has none. If you need shared recoverability, push branches or tags before risky operations.
Quick Check
Test your understanding of Git recovery tools.
Recap
You learned Git's safety nets: the reflog recovers from bad resets and rebases, cherry-pick restores single lost commits, the stash protects work-in-progress, fsck hunts dangling objects, and the GC clock means you should recover promptly. Git rarely loses data if you know where to look.
Pertanyaan yang Sering Diajukan
Apakah pelajaran “Menyelamatkan Pekerjaan dengan Reflog dan Stash” gratis?
Ya — teks lengkap “Menyelamatkan Pekerjaan dengan Reflog dan Stash” 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 “Menyelamatkan Pekerjaan dengan Reflog dan Stash”?
Kuasai jaring pengaman Git: gunakan reflog untuk memulihkan keadaan setelah reset dan rebase yang keliru, serta gunakan stash untuk menyisihkan dan memulihkan pekerjaan yang sedang berlangsung dengan… 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 4 dari 4.
Berapa lama pelajaran “Menyelamatkan Pekerjaan dengan Reflog dan Stash” 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
- Memulihkan Commit dan Cabang yang Hilang
- Men-debug dengan Git Bisect
- Mengoptimalkan Kinerja Repositori Git
- Menyelamatkan Pekerjaan dengan Reflog dan Stash