Git Common Mistakes
In this page:
गलत Branch पर Commit करना
जब आप एक feature branch पर होना चाहते थे तब सीधे main में commit करना काम खोए बिना fix करने लायक है: अपनी current commit पर एक नई branch बनाएँ, फिर main को वापस उसकी पहले वाली position पर reset करें (git reset --hard origin/main) ताकि commit सिर्फ नई branch पर रहे।
उदाहरण: Committing to the Wrong Branch
git branch feature-x
git reset --hard HEAD~1
git checkout feature-x
एक File Add करना भूल जाना
यह realize करना कि आप पहले से commit करने के बाद एक file git add करना भूल गए एक बिल्कुल नई commit की माँग नहीं करता — missing file stage करें और अभी बनाई commit में इसे fold करने के लिए git commit --amend --no-edit चलाएँ, जब तक आपने अभी push न किया हो।
उदाहरण: Forgetting to Add a File
git add forgotten-file.txt
git commit --amend --no-edit
Accidental Hard Reset
एक git reset --hard जो intended से ज़्यादा पीछे जाता है catastrophic महसूस होता है, लेकिन commits आमतौर पर actually delete नहीं होतीं — git reflog अभी भी record रखता है कि आपकी branch थोड़ी देर पहले कहाँ point करती थी, इसलिए आप पुराना commit hash ढूँढकर उस पर वापस reset कर सकते हैं।
उदाहरण: Accidental Hard Reset
git reflog
git reset --hard a1b2c3d
Messy States Fix करना
जब एक merge या rebase आपकी branch को एक ऐसी state में छोड़ दे जिसे आप समझते और trust नहीं करते, बाहर निकलने का सबसे तेज़ तरीका अक्सर इससे लड़ते रहना नहीं है — git reset --hard origin/<branch> local confusion फेंक देता है और आपको remote पर सबसे हाल की known-good state के साथ realign कर देता है (किसी भी uncommitted local काम की कीमत पर)।
उदाहरण: Fixing Messy States
git reset --hard origin/main
पहले से Tracked एक File को Untrack करना
पहले से Git द्वारा tracked एक file के लिए .gitignore में add करना कुछ नहीं करता — ignore rules सिर्फ *untracked* files पर apply होते हैं। इसे track करना रोकने के लिए आपको पहले git rm --cached <file> चलाना होगा, और तभी .gitignore actually इसे future commits से बाहर रखता है।
उदाहरण: Untracking an Already Tracked File
echo "config.local.json" >> .gitignore
git rm --cached config.local.json
- गलती से
mainपर commit करना और branch पर काम save करने से पहलेgit reset --hardइस्तेमाल करना, commits खोते हुए। - एक भूली हुई file के लिए एक नई commit बनाना बजाय
git commit --amend --no-editइस्तेमाल करने के, history को गंदा करते हुए। - एक गलत
git reset --hardके बाद panic करना और यह मान लेना कि commits चली गईं, जबकिgit reflogआमतौर पर दिखाता है कि उन्हें कैसे recover करना है।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: