Git stash Command
In this page:
git stash
git stash list
git stash apply [stash@{n}]
git stash pop
Git Stash क्या है?
git stash आपके uncommitted changes (staged और unstaged) लेता है और उन्हें एक अलग stack पर store करता है, आपकी working directory को last commit से match करने पर reset करते हुए। यह tasks switch करने का सबसे तेज़ तरीका है — कोई दूसरी branch checkout करना, एक urgent bug fix करना — बिना अपनी tree साफ करने के लिए आधे-अधूरे काम को commit किए।
उदाहरण: What is Git Stash?
git stash
Stashes List और View करना
git stash list आपकी save की हर stash दिखाता है, सबसे हाल की पहले, और git stash show -p stash@{n} आपको वापस लाने का decide करने से पहले किसी specific के अंदर का actual diff देखने देता है। यह तब मायने रखता है जब आपके पास एक से ज़्यादा stash हों और आपको याद न रहे कौन सी कौन है।
उदाहरण: Listing and Viewing Stashes
git stash list
git stash show -p stash@{0}
Stash Apply और Pop करना
git stash apply एक stash के changes को आपकी working directory में फिर apply करता है लेकिन इसे बाद में reuse के लिए stash list में छोड़ देता है — कई branches पर same changes चाहिए होने पर handy। git stash pop वही करता है लेकिन इसे list से भी हटा देता है, जो common one-time case के लिए आप चाहते हैं।
उदाहरण: Applying and Popping Stash
git stash apply
git stash pop
Specific Files Stash करना
आप एक साथ सब कुछ stash करने तक limited नहीं हैं -- git stash push -- <file> सिर्फ specific files stash करता है, और git stash push --patch आपको interactively individual hunks चुनने देता है, तब उपयोगी जब आपके working changes का सिर्फ हिस्सा अलग रखने के लिए ready हो।
उदाहरण: Stashing Specific Files
git stash push -- file.txt
Stash Clean करना
अगर आप कभी उन्हें साफ न करें तो पुरानी stashes बस space लेती और list गंदी करती रहती हैं। git stash drop stash@{n} एक specific entry हटाता है, जबकि git stash clear पूरी stash list मिटा देता है -- बाद वाला irreversible है, इसलिए पहले double-check करें कि आपको उनमें से कोई नहीं चाहिए।
उदाहरण: Cleaning the Stash
git stash drop stash@{0}
git stash clear
git stashचलाना और untracked files के भी save होने की उम्मीद करना, जबकि जब तक आप-uइस्तेमाल न करें वे छूट जाती हैं।git stash popइस्तेमाल करना और एक conflict मिलना, फिर यह मान लेना कि stash गायब हो गया, जबकि Git conflict पर इसे list में रखता है।- उन्हें नाम न देकर stashes का track खोना, जबकि
git stash push -m "message"औरgit stash listउन्हें identify करना आसान बनाते हैं।
Chapter Quiz — Complete all 18 topics to unlock
0/18 topics done
Complete these topics first:
- Git init Command
- Git New Files
- Git Staging Environment
- Git clone Command
- Git status Command
- Git help Command
- Git add Command
- Git commit Command
- Git tags Command
- Git stash Command
- Git log Command
- Git diff Command
- Git show Command
- Git rm Command
- Git mv Command
- Git restore Command
- Git clean Command
- Git ignore (.gitignore)