GitReel #40 · 8 Nov 2026
git reset --hard se code gaya? git reflog se wapas lao
git reset --hard branch ko purane commit par le jaata hai aur working files overwrite kar deta hai. Lekin jo commits pehle ban chuke the wo turant delete nahi hote. Git har HEAD movement (commit, reset, checkout, merge) apne local reflog mein likhta hai. git reflog se reset se pehle wala hash dhoondo aur wapas jao. Limits: bina commit kiye changes reflog mein nahi hote, reflog sirf tumhare local repo mein hota hai (fresh clone mein nahi), aur reset se chhoote commits ki entries default 30 din baad expire hoti hain (baaki entries 90 din).
Links
Aaj ye karo
- Ruko: git gc ya git reflog expire mat chalao, warna purani entries saaf ho sakti hain.
- git reflog chalao. Har line mein ek hash, HEAD@{n} aur action hota hai, jaise reset: moving to HEAD~3 ya commit: payment page done.
- Reset wali line ke theek neeche wali line hi reset se pehle ki state hai. Uska hash copy karo (example: c4d8b21).
- Safe tareeka: pehle git branch rescue c4d8b21 banao aur git log rescue se check karo ki sab commits hain.
- Phir git reset --hard c4d8b21 chalao. Branch wapas usi commit par, files wapas.
- Abhi abhi reset kiya hai? git reset --hard ORIG_HEAD bhi kaam karta hai, kyunki reset purani jagah ORIG_HEAD mein rakhta hai.
- Limits: uncommitted changes reflog mein nahi hote. Reflog sirf local hai. Reset se chhoote commits ki entries default 30 din (gc.reflogExpireUnreachable), baaki 90 din (gc.reflogExpire).
- Aadat: reset se pehle git stash ya chhota commit. Chhote commits = zyada recovery points.
git refloggit reflog -n 20git branch rescue c4d8b21git reset --hard c4d8b21git reset --hard ORIG_HEADgit stashSources
git-scm.com docs (git-reflog, git-reset, git-config gc.reflogExpire aur gc.reflogExpireUnreachable) aur Pro Git book; 8 Nov 2026 ko check kiya.
howitworks