259

I tried to merge my branch with another branch and there was a merge conflict. In Visual Studio Code (version 1.2.1) I resolved all of the issues, however when I try to commit it keeps giving me this message:

You should first resolve the un-merged changes before committing your changes.

I've tried googling it but I can't find out why it won't let me commit my changes, all of the conflicts have disappeared.

annedroiid
  • 6,267
  • 11
  • 31
  • 54
  • 2
    While what you've said is correct, it doesn't solve the issue in the question. I explicitly stated I've already solved all of the merge conflicts in the question. – annedroiid Jan 31 '19 at 14:36
  • Well yes, there is a ton of material on resolving conflicts in VS Code, BUT -- what about "both deleted" conflict! If I press the "plus sign" (stage, i.e. "git add"), this causes a confirmation prompt, then IDE hangs for a while, and then the file is gone from changes (seems not staged as a delete). I would assess this functionality as "needs work"! – Tomasz Gandor Mar 24 '22 at 07:11
  • The current answers cover the “old” merge editor. For the new 3-way merge editor, check this thorough guide, for instance: [Finally Released: 3-Column Merge Editor in VS Code!](https://javascript.plainenglish.io/finally-released-3-column-merge-editor-in-vs-code-8490ef694b3a) – Melebius Aug 15 '22 at 10:55

8 Answers8

256

With VSCode you can find the merge conflicts easily with the following UI. enter image description here

(if you do not have the topbar, set "editor.codeLens": true in User Preferences)

It indicates the current change that you have and incoming change from the server. This makes it easy to resolve the conflicts - just press the buttons above <<<< HEAD.

If you have multiple changes and want to apply all of them at once - open command palette (View -> Command Palette) and start typing merge - multiple options will appear including Merge Conflict: Accept Incoming, etc.

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
178

After trial and error I discovered that you need to stage the file that had the merge conflict, then you can commit the merge.

annedroiid
  • 6,267
  • 11
  • 31
  • 54
  • 1
    Yes, correct. Any commit, whether that is merge conflict or your local commit that you are trying to push needs to be staged before you can push that commit. – surendrapanday Feb 26 '19 at 06:44
  • 3
    For those who are confused if `git add .` doesn't stage all files, check if you're in the root directory of the project. Took me sometime to figure that out. Then `git add .` to stage all files, and then it allowed me to `git merge --continue` – bensadiku Mar 27 '20 at 17:43
  • 5
    And after resolving the merge conflict, you must first SAVE the conflicted file before staging the merged changes. – nclark Aug 05 '20 at 22:08
  • 1
    @nclark have you ever found a way of automatically saving after accepting incoming files? – jackhowa Dec 08 '20 at 11:29
  • This solved my problem. Had to stage 2/7 files from VS Code – WhooNo Dec 21 '21 at 20:15
53
  1. Click "Source Control" button on left.
  2. See MERGE CHANGES in sidebar.
  3. Those files have merge conflicts.

VS Code > Source Control > Merge Changes (Example)

Geoffrey Hale
  • 10,597
  • 5
  • 44
  • 45
  • 26
    I used to have the options "Accept Current Change | Accept Incoming Change..." but now these options just disappeared from the line, any idea how to reveal this options again? – jet_choong Apr 16 '20 at 04:40
  • 1
    This is so easy from the UI. Thanks for pointing out that **Merge Changes** section from the sidebar. – klewis Nov 12 '20 at 16:26
  • I agree with jet_choong. I no longer get the blue/green highlighting nor the "Accept Current Changes" CodeLens choice, even though setting "Merge-conflict › Code Lens" is enabled. Any idea how to fix? – Patrick Szalapski Sep 01 '22 at 15:46
48

For those who are having a hard time finding the "merge buttons".

The little lightbulb icon with the merge options only shows up if you click precisely on the "merge conflict marker":

<<<<<<<

Steps (in VS Code 1.29.x):

Jonathan Van Dam
  • 630
  • 9
  • 23
Felix K.
  • 14,171
  • 9
  • 58
  • 72
17

For VS Code 1.38 or if you could not find any "lightbulb" button. Pay close attention to the greyed out text above the conflicts; there is a list of actions you can take.

Qiang Li
  • 1,099
  • 11
  • 8
16

The error message you are getting is a result of Git still thinking that you have not resolved the merge conflicts. In fact, you already have, but you need to tell Git that you have done this by adding the resolved files to the index.

This has the side effect that you could actually just add the files without resolving the conflicts, and Git would still think that you have. So you should be diligent in making sure that you have really resolved the conflicts. You could even run the build and test the code before you commit.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
1

If there are conflicts: Use vs-code to solve them file by file. Click button "complete merge" in vs-code after every file. When there are no files left, run command:

git commit

( Don't rely on the vs-code "commit" button, it will be grayed out, which is wrong. )

Sunny127
  • 265
  • 3
  • 8
0

For VSCode 1.70.2 in merge view from source control panel there are checkboxes on "yours" and "theirs" sides, next to the line numbers in the middle of selected conflict block, instead of text buttons above lines.

Misiur
  • 5,019
  • 8
  • 38
  • 54
  • What do you do after resolving all conflicts in this view? I Can't seem to find a way to apply the change to the file, other than copying from the Result pane and pasting in the actual file... – markmoxx Sep 26 '22 at 15:55