← Back to Git Course | Chapter 2: Basic Commands | Lesson 10 of 18

Git stash Command

git stash आपके desk पर mess को एक drawer में झाड़ देने जैसा है ताकि आप किसी urgent चीज़ पर शुरू कर सकें, फिर बाद में mess को वापस लाकर continue कर सकें।
Syntax
bash
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?

bash
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

bash
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

bash
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

bash
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

bash
git stash drop stash@{0}
git stash clear
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. git stash चलाना और untracked files के भी save होने की उम्मीद करना, जबकि जब तक आप -u इस्तेमाल न करें वे छूट जाती हैं।
  2. git stash pop इस्तेमाल करना और एक conflict मिलना, फिर यह मान लेना कि stash गायब हो गया, जबकि Git conflict पर इसे list में रखता है।
  3. उन्हें नाम न देकर stashes का track खोना, जबकि git stash push -m "message" और git stash list उन्हें identify करना आसान बनाते हैं।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.