← Back to Git Course | Chapter 5: Undoing Changes | Lesson 1 of 6

Git reset Command

git reset एक video को एक पहले वाले scene पर rewind करने जैसा है ताकि बाद के scenes उस branch पर आपकी story का हिस्सा न रहें।
Syntax
bash
git reset --soft commit_reference
git reset [--mixed] commit_reference
git reset --hard commit_reference

Git Reset क्या है?

git reset आपकी current branch को एक पहले वाली commit की ओर point करने के लिए rewind करता है, effectively उस point के बाद की commits को undo करते हुए जहाँ तक branch history का सवाल है। git revert के उलट, यह ऊपर एक नई commit add करने के बजाय history बदलता है, जो powerful है लेकिन shared branches पर ज़्यादा risky।

उदाहरण: What is Git Reset?

bash
git reset a1b2c3d

Soft Reset

--soft सिर्फ branch pointer वापस move करता है — आपके staged changes और working directory files exactly वैसे रहते हैं जैसे थे, इसलिए "undone" commits से सब कुछ staged changes की तरह वापस दिखता है जो फिर से अलग तरीके से commit होने के लिए ready हैं। यह सबसे safe reset mode है और कई छोटी commits को एक में squash करने का एक common तरीका।

उदाहरण: Soft Reset

bash
git reset --soft HEAD~1

Mixed Reset (Default)

Default mode (कोई flag नहीं, या --mixed) branch pointer वापस move करता है और staging area भी खाली कर देता है, लेकिन आपकी working directory files untouched छोड़ता है — इसलिए आपके edits survive करते हैं, बस अब staged नहीं। इसे तब इस्तेमाल करें जब आप दोबारा commit करने से पहले changes को review और re-stage करना चाहें।

उदाहरण: Mixed Reset (Default)

bash
git reset HEAD~1
git reset --mixed HEAD~1

Hard Reset (Dangerous)

--hard branch pointer वापस move करता है AND staging area और आपकी working directory दोनों को उस commit से exactly match करने के लिए overwrite करता है, इस process में किसी भी uncommitted work को permanently discard करते हुए। कोई confirmation prompt नहीं है, इसलिए इसे चलाने से पहले double-check करें कि आप actually उन changes को खोना चाहते हैं।

उदाहरण: Hard Reset (Dangerous)

bash
git reset --hard HEAD~1

Reset से Recover करना

एक hard reset के बाद भी, वे commits जो आपने "खोई" आमतौर पर गई नहीं होतीं — Git का reflog एक record रखता है कि आपकी branch tip हाल ही में कहाँ point कर चुकी है, इसलिए आप पुराना commit hash लुकअप करके उस पर वापस reset कर सकते हैं। यही safety net है जिस वजह से hard resets, भले ही scary हों, reflog की retention window के अंदर शायद ही कभी truly catastrophic होते हैं।

उदाहरण: Recovering from Reset

bash
git reflog
git reset --hard a1b2c3d
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 reset --hard HEAD~1 चलाना और uncommitted changes खो देना बिना working tree के through उन्हें वापस पाने के किसी तरीके के।
  2. पहले से pushed commits पर git reset इस्तेमाल करना, जो shared history rewrite करता है।
  3. modes को confuse करना, --mixed के files staged रखने की उम्मीद करना, जबकि --soft उन्हें staged रखता है और --mixed (default) उन्हें unstage करता है।
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

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.