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
- Open your code editor (like VS Code).
- Find the marked files (VS Code provides buttons like "Accept Current Change").
- Edit the code by removing the markers and keeping the final desired code.
- Save the file.
- Run
git add .andgit committo finish the merge.
Practical Exercise (Simulate a conflict)
- On
main, createapp.jswith text:const v = 1;and commit. - Create
branch-aand switch to it. Change line toconst v = 2;, and commit. - Go back to
main. Change line toconst v = 3;, and commit. - On
main, try:git merge branch-a. - BOOM! Conflict. Open
app.js, resolve it, remove markers, save,git add .andgit commit.
