World map

 

BM: Baca dalam Bahasa Melayu

World 3: Parallel Universes

Fix conflicts in VS Code

You will learn: to fix a conflict, finish the merge, or cancel it safely.

The problem

The merge of cake into main stops. A red Conflict badge with a warning sign sits under HEAD.
6d3a9b1a8feb63270a76e0c66136013a957

Your merge with cake stopped on a conflict. Time to fix it. Calmly, in three small steps.

Watch

Tap the glowing dots to explore.

0 of 5 explored

Open the file in VS Code. It paints each side and puts buttons above the clash. Tap the dots.

Try it

Your diary had both on day 2! Keep both lines. Then finish the merge.

Pick what stays in each conflict. Then finish.

6d3a9b1a8feb63270a76e0c66136013a957

Conflicts left: 1 of 1

index.htmlboth modified

<h1>My Diary</h1>
<p>Day 1: I learned Git.</p>
<<<<<<< HEAD (conflict marker)
current line: <p>Day 2: I learned branches.</p>
======= (conflict marker)
incoming line: <p>Day 2: I baked a cake.</p>
>>>>>>> cake (conflict marker)

Watch

index.html, fixed, slides from the working folder into the box. Then a commit called Merge branch 'cake' lands in the repository.

git add index.html tells Git: this file is fixed. Then git commit makes the merge commit. The + and Commit buttons in VS Code do the same.

Try it

Not ready to choose? Cancel the merge. Everything goes back to before.

6d3a9b1a8feb63270a76e0c66136013a957

Predict

You fixed the file but forgot git add. You run git commit. What happens?

Pick one answer.

Check

Put the conflict fix in order.

First step at the top. Put these in order. Use the arrows, or drag.

  • git commit to finish the merge
  • Open the file with the conflict
  • Pick what stays and delete the markers
  • git add the file

You did it!

You can now fix a merge conflict, or cancel it safely.

Go deeper (optional)

VS Code’s Merge Editor shows yours, theirs and the result together. From the terminal, git mergetool opens a merge tool you set up. git merge --abort works until you commit the merge. After that, undo it like any commit.