Logo hdtoledo
hdtoledo.dev
Módulos_del_Sistema
EJERCICIO_PRÁCTICO

Resolving Merge Conflicts

Resolving Merge Conflicts

A conflict occurs when two branches modify the exact same line of the same file, and when you try to merge, Git doesn't know which version to keep.

Conflict Anatomy

text
<<<<<<< HEAD <h1>Original</h1> ======= <h1>Changed</h1> >>>>>>> other-branch

How to resolve it

  1. Open your code editor (like VS Code).
  2. Find the marked files (VS Code provides buttons like "Accept Current Change").
  3. Edit the code by removing the markers and keeping the final desired code.
  4. Save the file.
  5. Run git add . and git commit to finish the merge.

Practical Exercise (Simulate a conflict)

  1. On main, create app.js with text: const v = 1; and commit.
  2. Create branch-a and switch to it. Change line to const v = 2;, and commit.
  3. Go back to main. Change line to const v = 3;, and commit.
  4. On main, try: git merge branch-a.
  5. BOOM! Conflict. Open app.js, resolve it, remove markers, save, git add . and git commit.