git reset
git
इस्तेमाल
git reset [--soft|--mixed|--hard] <commit> | git reset <path>branch के pointer को दूसरे commit पर ले जाता है: --soft सब कुछ staged छोड़ता है, --mixed (डिफ़ॉल्ट) staging भी खाली करता है पर बदलाव फ़ाइलों में रहते हैं, और --hard उन बदलावों को भी हमेशा के लिए मिटा देता है।
आम विकल्प
| विकल्प | अर्थ |
|---|---|
| --soft | move the branch only; index and files keep everything, so the change stays staged |
| --mixed | default: also clear the staging area, leaving edits in your files |
| --hard | also overwrite your files; uncommitted work is destroyed |
| <path> | no commit given: unstage that path |
| --keep | move but refuse if it would overwrite a local change |
| --merge | like --hard but keeps changes that do not collide |
उदाहरण
git reset --soft HEAD~1undoes the last commit and leaves everything staged
git reset HEAD~1undoes the last commit; the changes sit in your files, unstaged
git reset src/app.tsunstages one file without changing it
git reset --hard origin/mainthrows away local commits AND uncommitted edits
उलझन यह है कि पीछे लौटने के कई रूप हैं — ब्रांच का इशारा हटाना और उलटने वाला कमिट जोड़ना एक बात नहीं।
कैसे पढ़ें
- बड़े कोष्ठक [ ] उस हिस्से को दिखाते हैं जिसे छोड़ा जा सकता है।
- तीन बिंदु … का मतलब है एक से ज़्यादा दिए जा सकते हैं।
- विकल्पों में बड़े-छोटे अक्षर मायने रखते हैं — कुछ कमांड में -r और -R अलग काम करते हैं।
आम सवाल
Q. git reset क्या करता है?
branch के pointer को दूसरे commit पर ले जाता है: --soft सब कुछ staged छोड़ता है, --mixed (डिफ़ॉल्ट) staging भी खाली करता है पर बदलाव फ़ाइलों में रहते हैं, और --hard उन बदलावों को भी हमेशा के लिए मिटा देता है।
Q. इसे कैसे लिखें?
git reset [--soft|--mixed|--hard] <commit> | git reset <path> — बड़े कोष्ठक वह हिस्सा दिखाते हैं जो छोड़ा जा सकता है।
Q. कितने विकल्प जानने लायक़ हैं?
यहाँ 6 दिए हैं; पूरी सूची man git में है। यह कमांड git में आती है।
मिलती-जुलती कमांड
man पेज: man git-reset