← Back to Git Course | Chapter 7: Collaboration | Lesson 4 of 6

Git Conflict Resolution

एक merge conflict दो लोगों के same sentence को अलग-अलग तरीकों से erase और rewrite करने जैसा है। Git guess नहीं कर सकता कि आप कौन सा चाहते हैं, इसलिए यह आपसे चुनने को कहता है।
Syntax
bash
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?

bash
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

bash
<<<<<<< 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

bash
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

bash
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

bash
git add file.txt
git rebase --continue
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. file को अभी भी <<<<<<<, ======= और >>>>>>> markers रखते हुए commit करना।
  2. दूसरी तरफ पढ़े बिना सिर्फ एक तरफ रखना, दूसरे developer के किए काम delete करते हुए।
  3. file fix करने के बाद git add भूल जाना, ताकि git commit कहे कि merge अभी भी unresolved है।
🔒

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.