209

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
  • 5,350
  • 9
  • 29
  • 52
  • 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

6 Answers6

215

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,112
  • 17
  • 72
  • 132
Sajeetharan
  • 203,447
  • 57
  • 330
  • 376
154

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
  • 5,350
  • 9
  • 29
  • 52
  • 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
  • 2
    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
  • 2
    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
45

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
  • 599
  • 8
  • 22
Felix K.
  • 11,650
  • 8
  • 53
  • 63
40
  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
  • 9,339
  • 5
  • 39
  • 43
  • 8
    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
15

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
  • 451,927
  • 24
  • 239
  • 318
11

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
  • 973
  • 10
  • 8