Git Conflict Resolution
In this page:
git merge branch_name
# edit the file to resolve the conflict markers
git add file_name
git commit
एक Merge Conflict क्या है?
एक merge conflict तब होता है जब जिस branch को आप merge कर रहे हैं और आपकी current branch दोनों ने diverge होने के बाद same file की same lines बदली हों, इसलिए Git के पास automatically यह decide करने का कोई तरीका नहीं है कि कौन सा version सही है और यह आपके हाथ से resolve करने के लिए merge pause कर देता है।
उदाहरण: What is a Merge Conflict?
git merge feature-x
# CONFLICT (content): Merge conflict in file.txt
Conflict Markers को समझना
Git हर conflicting section को file में सीधे <<<<<<<, =======, और >>>>>>> lines से mark करता है जो "आपके" version को "उनके" version से separate करती हैं। Conflict resolve करने का मतलब है file को edit करना ताकि सही content रहे — एक तरफ से, दूसरी से, या एक manual combination — और तीनों marker lines को पूरी तरह delete करना।
उदाहरण: Understanding Conflict Markers
<<<<<<< HEAD
your version
=======
their version
>>>>>>> feature-x
Resolution Stage और Commit करना
एक बार हर conflict marker चला जाए और file वह outcome reflect करे जो आप चाहते हैं, git add <file> resolution stage करता है और git commit merge खत्म करता है — Git को पहले से पता है कि एक merge progress में था, इसलिए यह आपके लिए एक merge commit message pre-fill कर देता है।
उदाहरण: Staging and Committing the Resolution
git add file.txt
git commit
एक Conflicting Merge Abort करना
अगर एक conflict अभी resolve करने लायक trouble से ज़्यादा साबित हो, git merge --abort merge को पूरी तरह cancel कर देता है और आपकी branch को exactly उस state में वापस लाता है जिसमें आप शुरू करने से पहले थे — जब तक आपने resolution पहले से commit न किया हो एक पूरा escape hatch।
उदाहरण: Aborting a Conflicting Merge
git merge --abort
एक Rebase के दौरान Conflicts Resolve करना
एक rebase के दौरान conflicts file-wise same तरीके से काम करते हैं, लेकिन continuation command अलग है: file fix और stage करने के बाद, आप अगली commit replay करने के लिए continue करने के लिए git rebase --continue चलाते हैं (commit नहीं) — और rebase में हर बाद की commit अपना अलग conflict trigger कर सकती है।
उदाहरण: Resolving Conflicts During a Rebase
git add file.txt
git rebase --continue
- file को अभी भी
<<<<<<<,=======और>>>>>>>markers रखते हुए commit करना। - दूसरी तरफ पढ़े बिना सिर्फ एक तरफ रखना, दूसरे developer के किए काम delete करते हुए।
- file fix करने के बाद
git addभूल जाना, ताकिgit commitकहे कि merge अभी भी unresolved है।
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: