Git Recovery
In this page:
git reflog
git branch recovered_branch commit_hash
git reset --hard commit_hash
एक Deleted Branch Recover करना
git branch -D से एक branch delete करना सिर्फ branch pointer हटाता है, इसकी referenced commits नहीं, इसलिए वे commits repository में तब तक रहती हैं जब तक garbage collection आख़िरकार unreachable वालों को न हटा दे। git reflog चलाना delete के बाद भी branch का last known commit hash दिखाता है, और उस hash की ओर point करने वाली एक नई branch बनाना branch को उसकी history सहित पूरी तरह वापस ले आता है।
उदाहरण: Recovering a Deleted Branch
git reflog
git branch recovered-branch a1b2c3d
एक Hard Reset के बाद Recover करना
एक git reset --hard branch pointer move करता है और उस पर मौजूद commits discard करता है, जो permanent लगता है लेकिन commits खुद आमतौर पर garbage collected होने तक reflog में survive करती हैं। git reflog चलाना reset से ठीक पहले की state के लिए एक entry दिखाता है, और उस hash पर दोबारा reset करना hard reset को ऐसे undo कर देता है जैसे यह कभी हुआ ही न हो।
उदाहरण: Recovering After a Hard Reset
git reflog
git reset --hard a1b2c3d
एक Uncommitted File Recover करना
अगर आप एक ऐसी file delete करें जो पहले किसी point पर staged या committed थी, git checkout (या newer Git में git restore) index या सबसे हाल की commit से last known version वापस खींच सकता है। यह सिर्फ उस content के लिए काम करता है जिसे Git पहले से जानता था — एक ऐसी file जो कभी staged या committed नहीं हुई उसका कोई recorded version नहीं है जिसे Git recover कर सके।
उदाहरण: Recovering an Uncommitted File
git checkout -- deleted-file.txt
git restore deleted-file.txt
git rm के बाद Recover करना
git rm एक step में working directory और staging area दोनों से एक file हटाता है, जो एक plain filesystem delete से ज़्यादा destructive है क्योंकि यह removal भी stage करता है। अगर removal अभी commit नहीं हुई है, git reset HEAD -- <file> के बाद एक checkout file को सीधे वापस ले आता है; अगर यह commit हो चुकी है, आपको removal से ठीक पहले वाली commit से file checkout करनी होगी।
उदाहरण: Recovering After git rm
git reset HEAD removed-file.txt
git checkout -- removed-file.txt
एक Stash से Recover करना
एक botched apply के बाद एक stash automatically delete नहीं होता, और यहाँ तक कि एक dropped stash का commit-like object अक्सर कुछ समय के लिए reflog में survive करता है, git fsck --unreachable से findable। अगर आपको roughly पता है कि इसमें क्या था, git stash list और git stash show आपको apply, pop, या drop करने का decide करने से पहले exact stash entry locate करने में मदद कर सकते हैं।
उदाहरण: Recovering from a Stash
git fsck --unreachable
git stash apply a1b2c3d
- यह मान लेना कि
git branch -Dयाgit reset --hardcommits को तुरंत destroy कर देता है, जबकि वेgit reflogमें कुछ समय के लिए findable रहती हैं। - एक deleted branch की commits के लिए
git logमें देखना, जो उन्हें नहीं दिखाएगा; इसके बजायgit reflogइस्तेमाल करें। - एक ऐसी file recover करने की कोशिश करना जो कभी staged या committed नहीं हुई, जिसे Git restore नहीं कर सकता क्योंकि यह कभी saved ही नहीं हुई।
git resetऔरgit revertcommits को अलग-अलग तरीकों से undo करते हैं।git reflogऔर recovery techniques खोया हुआ काम वापस लाने में मदद करती हैं।- एक commit amend करना और
restoreतथाcheckoutइस्तेमाल करना हाल की गलतियाँ fix करते हैं।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: