Git reflog Command
In this page:
git reflog
git reset --hard HEAD@{n}
Git Reflog क्या है?
git reflog उन हर जगहों का एक chronological log दिखाता है जहाँ आपकी local repository में HEAD (और हर branch) ने point किया है, commits, checkouts, resets, और rebases सहित। क्योंकि यह commit graph के बजाय *reference movements* track करता है, यह ऐसा काम ढूँढ सकता है जो अब किसी branch से reachable नहीं है — exactly उस तरह की "lost" commit जो एक hard reset या rebase पीछे छोड़ देता है।
उदाहरण: What is Git Reflog?
git reflog
Reflog पढ़ना
हर reflog entry एक commit hash को उस action के साथ pair करता है जिसने इसे produce किया (जैसे commit, checkout: moving from..., reset: moving to...), जो आपको exactly reconstruct करने देता है कि आपने क्या किया और कब, entry by entry, सबसे हाल की पहले।
उदाहरण: Reading the Reflog
git reflog
# a1b2c3d HEAD@{0}: commit: Fix login bug
# e4f5g6h HEAD@{1}: checkout: moving from main to feature-x
Lost Commits Restore करना
किसी ऐसी commit को recover करने के लिए जिसकी ओर अब कोई branch point नहीं करती, reflog में इसका hash ढूँढें और इसे inspect करने के लिए git checkout <hash> या इसे एक real branch पर वापस लाने के लिए git reset --hard <hash> / git branch recovery <hash> इस्तेमाल करें। commit खुद कभी delete नहीं हुई — सिर्फ इसका reference हुआ।
उदाहरण: Restoring Lost Commits
git reflog
git reset --hard a1b2c3d
Deleted Branches Restore करना
एक branch delete करना भी उसकी commits तुरंत delete नहीं करता — reflog अभी भी याद रखता है कि उस branch की tip कहाँ थी। deleted branch जिस last commit hash की ओर point करती थी उसे लुकअप करें और इसे exactly वैसे recreate करने के लिए git branch <name> <hash> चलाएँ जैसे यह थी।
उदाहरण: Restoring Deleted Branches
git reflog
git branch recovered-branch a1b2c3d
Reflog Lifetimes Manage करना
Reflog entries हमेशा के लिए नहीं रहतीं — unreachable वाली एक configurable window (default 90 days, अगर बनते समय पहले से unreachable हों तो 30) के बाद expire हो जाती हैं इससे पहले कि Git का garbage collector उन्हें prune कर सके। git reflog expire और git gc आपको ज़रूरत पड़ने पर जल्दी disk space reclaim करने के लिए manually इसे control करने देते हैं।
उदाहरण: Managing Reflog Lifetimes
git reflog expire --expire=90.days.ago --all
- यह सोचना कि
git reflogremote के साथ shared है, जबकि यह सिर्फ local है और कभी push नहीं होता। - lost commits ढूँढने के लिए बहुत देर तक wait करना, जबकि पुरानी reflog entries expire होती हैं (default रूप से लगभग 90 दिनों के बाद) और garbage collected हो सकती हैं।
git reflogचलाना और गलत entry चुनना, जबकिHEAD@{n}numbers हर नई action के साथ बदलते हैं।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: