Git Course 0%

The merge editor

Intermediate VS Code UI ≈ 10 min

What you will learn

  • What appears when a merge conflicts, and where
  • The inline actions and when they are enough
  • The three-way merge editor, pane by pane

After this lesson you can

  • I can resolve a conflict in VS Code without falling back to the terminal

Why this matters

Conflicts are the moment people abandon a graphical tool and ask for help. VS Code's merge editor is genuinely good at this, and it shows the one thing the raw markers hide: what the line looked like before either side changed it.

What happens when a merge conflicts

A merge that cannot be resolved automatically leaves the repository mid-merge (Section 11). VS Code shows:

  • The conflicted files under a Merge Changes section in the Source Control view.
  • The conflict markers in the file, with inline actions above each block.
  • A Resolve in Merge Editor button at the top of the file.

Nothing has been decided yet, and nothing is broken. The merge is paused, waiting for you.

The inline actions

Above each conflicting block, VS Code offers four CodeLens actions:

Action Keeps
Accept Current Change Your branch's version
Accept Incoming Change The other branch's version
Accept Both Changes Both, one after the other
Compare Changes Opens a diff of the two, deciding nothing

These are enough when the answer is obvious: one side is clearly right, or both belong. They are not enough when the correct result is a sentence neither side wrote, which is common in documentation.

The merge editor

Click Resolve in Merge Editor for the three-pane view:

The VS Code merge editor, labelled A schematic of the three-way merge editor. Two panes across the top show Incoming on the left, the version from the branch being merged, and Current on the right, the version on the branch you are on. Each conflicting block has a checkbox to include it. The bottom pane, Result, shows the merged file being built as you choose. A Complete Merge button sits at the bottom right, and a note says it stages the file. Callouts explain that Incoming is theirs, Current is yours, the Result pane is editable so you can type a third wording, and that the alternative to the merge editor is the inline CodeLens actions Accept Current Change, Accept Incoming Change and Accept Both Changes shown directly in the file. Incoming docs/12-windows-install-steps ☐ Yes. Trailguide is free for everyone. …unchanged lines… …unchanged lines… Current main ☐ Yes. A practice project; costs nothing. …unchanged lines… …unchanged lines… Result the file that will be committed — editable Yes. Trailguide is free for everyone, including commercial use. …unchanged lines… Complete Merge stages the resolved file Incoming = theirs · Current = yours · Result = what gets committed, and you may type a third wording. Without the merge editor, the same choices appear inline: Accept Current · Accept Incoming · Accept Both.
Incoming and Current across the top, Result at the bottom, and Complete Merge to finish. The Result pane is editable.
Pane Is
Incoming (left) The version from the branch being merged in
Current (right) The version on the branch you are on
Result (bottom) The file that will be committed

Each conflicting block has checkboxes in the top panes: tick one, or both, and the Result updates. The Result pane is an ordinary editor, so you can also type something neither side wrote, which is usually the right answer when two people rewrote the same sentence.

When every conflict is decided, Complete Merge stages the file and closes the editor. The file moves from Merge Changes to Staged Changes, and the merge is finished by committing.

Finishing, or escaping

Situation Action
All conflicts resolved Complete Merge, then commit from the Source Control view
Several conflicted files Resolve each; the merge is not done until all are staged
You want out Command Palette → Git: Abort Merge
You want out of a rebase Git: Abort Rebase, or the Abort action in the Source Control view

Aborting returns you exactly to where you were (lesson 12.6). It is a perfectly respectable choice when the right resolution needs a conversation.

Reading the result before committing

After resolving, before committing, click the file under Staged Changes and read the diff. Two things go wrong at this stage and both are visible there:

  • A leftover marker: a stray <<<<<<< or ======= that was not removed. The linter or the build usually catches it, embarrassingly and later.
  • A half-resolved sentence that reads oddly because it combines two wordings.

That check takes ten seconds and it is the difference between resolving a conflict and appearing to.

How to do it

The same conflict, in commands:

Terminal
$ git status              # which files are unmerged
$ git diff                # the conflict, with markers
# edit the file
$ git add docs/faq.md
$ git commit              # finishes the merge

Turning on the better marker style makes the terminal view much closer to the merge editor's (lesson 11.2):

Terminal
$ git config --global merge.conflictstyle zdiff3

Common mistakes

  • Assuming "Current" is always yours. During a rebase it is not.
  • Accepting one side to make the conflict go away, and losing the other person's change silently.
  • Leaving a marker in the file.
  • Committing without reading the staged diff.
  • Fixing a conflict you do not understand. Ask the other author; git log names them (lesson 11.6).

Try it yourself

Goal: resolve a real conflict in the merge editor.

  1. On your practice project, create two branches that change the same line of docs/faq.md differently, and commit both.
  2. Merge one into the other from VS Code (Git: Merge Branch…) and watch Merge Changes appear.
  3. Try the inline actions first: click Accept Both Changes and read the result.
  4. Undo that, click Resolve in Merge Editor, and this time type a third wording into the Result pane.
  5. Complete Merge, read the staged diff, and commit.

Expected result: one conflict resolved two ways, with a final version that says what you meant rather than what either branch happened to say.

Show solution

Step 4 is the reason the merge editor exists. Most documentation conflicts are two people improving the same sentence, and the correct resolution is neither version: it is the one you write while looking at both. The Result pane being editable is what makes that a thirty-second job.

Check yourself

1. What are the three panes of the merge editor?
2. During a rebase, which side is "Current"?
3. What does Complete Merge do?

Key terms

Merge conflict Merge Staged