🌐 Detecting your location…
📢 Advertisement — Configure AdSense in Appearance → Customize → AdSense Settings

गिट स्टैश: संपूर्ण गाइड – स्टैश से सेव, अप्लाई, पॉप, ड्रॉप और ब्रांच

⏱️4 min read  ·  676 words

git stashआपके कार्यशील निर्देशिका परिवर्तनों को अस्थायी रूप से सहेजता है ताकि आप अधूरा कार्य किए बिना संदर्भ बदल सकें। यह सबसे उपयोगी लेकिन कम उपयोग किए गए Git कमांड में से एक है। यह मार्गदर्शिका प्रत्येक उप-कमांड को व्यावहारिक उदाहरणों के साथ कवर करती है।

मूल संकल्पना

# You're in the middle of feature work and need to switch branches
git status
# M  src/auth.ts    ← modified
# M  src/utils.ts   ← modified
# ?? src/new-file.ts  ← untracked

git checkout main  # ERROR: would overwrite changes

# git stash saves and cleans your working directory
git stash
# Saved working directory and index state WIP on feature: abc123 Add auth

git checkout main  # ✅ now clean working tree

# ... do what you needed on main ...

git checkout feature
git stash pop      # restore your changes

गिट स्टैश कमांड्स

# Save stash with a message (recommended — harder to forget what it was)
git stash push -m "WIP: auth middleware refactor"

# Short form (saves tracked changes only)
git stash

# Include untracked files
git stash push --include-untracked   # or -u

# Include untracked AND ignored files (rare)
git stash push --all                 # or -a

# Partial stash — choose specific files
git stash push -m "just auth changes" -- src/auth.ts src/auth.test.ts

गुप्त वस्तुओं की सूची बनाना और उनका निरीक्षण करना

# List all stashes
git stash list
# stash@{0}: WIP on feature: abc123 Add auth
# stash@{1}: WIP on main: def456 Fix bug
# stash@{2}: On feature: Manual save before experiment

# Show what's in a stash (summary)
git stash show            # most recent
git stash show stash@{1} # specific stash

# Show full diff of a stash
git stash show -p stash@{0}

पुनर्स्थापित करना: पॉप बनाम लागू

# git stash pop — apply AND remove from stash list
git stash pop              # applies stash@{0} and removes it
git stash pop stash@{2}   # apply a specific stash

# git stash apply — apply but KEEP in stash list
git stash apply            # applies stash@{0}, keeps it in list
git stash apply stash@{1}

# When to use apply:
# - When you want to apply the same stash to multiple branches
# - When you're not sure the apply will be clean and want to retry
# - As a safety measure — you can always drop manually after

स्टैश लागू करते समय संघर्ष

# If the stash conflicts with current branch state:
git stash pop
# CONFLICT (content): Merge conflict in src/auth.ts
# The stash entry is NOT removed when conflicts occur

# Fix conflicts normally
git add src/auth.ts
git stash drop    # manually remove the stash after resolving
# (pop would have removed it automatically if no conflicts)

एक छिपाने की जगह से शाखा

# Create a new branch FROM the commit where the stash was saved
# and apply the stash to it — useful when stash won't apply cleanly to current branch
git stash branch my-new-branch stash@{0}

# This is equivalent to:
# git checkout -b my-new-branch stash-parent-commit
# git stash apply stash@{0}
# git stash drop stash@{0}

गुप्त वस्तुएं हटाना

# Remove specific stash
git stash drop stash@{0}

# Remove most recent stash
git stash drop

# Remove ALL stashes (dangerous — no undo)
git stash clear

इंटरएक्टिव मोड के साथ आंशिक स्टैश

# Interactively choose which hunks to stash (like git add -p)
git stash push --patch    # or -p

# Shows each changed hunk and asks: stash this hunk? (y/n/d/a/e/?)
# Useful when a file has changes you want to stash and changes you want to keep

सामान्य डेवलपर वर्कफ़्लोज़

# Workflow 1: Quick context switch
git stash push -m "WIP: new feature"
git checkout main
git pull origin main
# ... fix urgent bug ...
git checkout feature
git stash pop

# Workflow 2: Stash before risky rebase
git stash push -u -m "Before rebase backup"
git rebase origin/main
# If rebase goes wrong: git stash pop restores your state
# (though git reflog is better for full recovery)

# Workflow 3: Test clean build
git stash push -u          # stash everything including untracked
npm run build              # verify clean build works
git stash pop              # restore your work

# Workflow 4: Apply stash to different branch
git stash push -m "shared config changes"
git checkout feature-a
git stash apply stash@{0}  # apply (keep in list)
git checkout feature-b
git stash apply stash@{0}  # apply to second branch too
git stash drop stash@{0}   # now drop it

गिट स्टैश बनाम गिट कमिट –अमेंड बनाम गिट वर्कट्री

परिदृश्य सर्वोत्तम उपकरण
त्वरित संदर्भ स्विच (वही मशीन, 5-30 मिनट) git stash
दो शाखाओं पर एक साथ कार्य करें git worktree add
रिमोट पर पुश करने की क्षमता के साथ WIP सहेजें git commit -m "WIP" (बाद में सुधार)
अंतिम प्रतिबद्धता पूर्ववत करें लेकिन परिवर्तन रखें git reset HEAD~1

अक्सर पूछे जाने वाले प्रश्न

प्रश्न: क्या गिट स्टैश सभी शाखाओं में काम करता है?
उत्तर: हाँ. स्टैश एक वैश्विक स्टैक है – शाखा-विशिष्ट नहीं। आप शाखा A पर स्टैश कर सकते हैं, शाखा B पर स्विच कर सकते हैं, और स्टैश को वहां पॉप कर सकते हैं। यदि फ़ाइलें शाखा बी के साथ संघर्ष करती हैं, तो आपको हल करने के लिए एक मर्ज विरोध मिलेगा।

प्रश्न: क्या git stash अनट्रैक की गई फ़ाइलों को सहेजेगा?
उत्तर: डिफ़ॉल्ट रूप से नहीं.git stash push -uका प्रयोग करें (या--include-untracked) नई अनट्रैक की गई फ़ाइलों को शामिल करने के लिए।git stash push -aका प्रयोग करें (या--all) ट्रैक न की गई और गिटइग्नोर्ड दोनों फाइलों को शामिल करने के लिए।

प्रश्न: मैंने गलती से अपना भंडार गिरा दिया – क्या मैं इसे पुनः प्राप्त कर सकता हूँ?
उत्तर: संभवतः. भागोgit fsck --no-reflog | awk '/dangling commit/ {print $3}' लटकते कमिट ढूँढ़ने के लिए। फिरgit show <hash> अपनी गुप्त सामग्री की पहचान करने के लिए, औरgit stash apply <hash> इसे पुनर्स्थापित करने के लिए. Git कचरा संग्रहण से पहले ~30 दिनों के भीतर काम करता है।

प्रश्न: मेरे पास कितनी चीज़ें हो सकती हैं?
उत्तर: कोई व्यावहारिक सीमा नहीं. लेकिन यदि आपके पास 10 से अधिक संग्रह हैं, तो इसके बजाय WIP करने या गिट वर्कट्री का उपयोग करने पर विचार करें – एक लंबी संग्रह सूची स्थगित निर्णयों का संकेत है।

प्रश्न: क्या मैं केवल चरणबद्ध परिवर्तनों को ही संग्रहित कर सकता हूँ?
उत्तर: हाँ:git stash push --staged केवल अनुक्रमणिका (चरणबद्ध) में जो कुछ है उसे संग्रहीत करता है, जिससे कार्यशील निर्देशिका में अपरिवर्तित परिवर्तन रह जाते हैं। परिवर्तनों को छोटी तार्किक इकाइयों में अलग करने के लिए उपयोगी।

निष्कर्ष

git stash अधूरा कार्य किए बिना स्वच्छ संदर्भ स्विचिंग के लिए आवश्यक है। मुख्य आदेश:git stash push -u -m "description" सहेजने के लिए (अनट्रैक किए गए सहित),git stash pop पुनर्स्थापित करने और हटाने के लिए,git stash apply पुनर्स्थापित करना और रखना।git stash branchका प्रयोग करें जब स्टैश आपकी वर्तमान शाखा पर स्पष्ट रूप से लागू नहीं होगा। भंडार एक LIFO स्टैक है – इसे सक्रिय रूप से बनाए रखें, उन भंडारों को हटा दें जिनकी आपको अब आवश्यकता नहीं है, और इसे 3-4 प्रविष्टियों से अधिक जमा न होने दें।

✍️ Leave a Comment

Your email address will not be published. Required fields are marked *

🌐 Read in:🇩🇪 Deutsch🇧🇷 Português🇸🇦 العربية🇮🇳 हिन्दी🇧🇩 বাংলা