Vscode: Git: Use VS Code as merge editor

Created on 25 Apr 2016  ·  96Comments  ·  Source: microsoft/vscode

1.0.0 introduced the ability to use VS Code as a git difftool. The relevant global .gitconfig lines are as follows:

[diff]
    tool = default-difftool
[difftool "default-difftool"]
    cmd = code --wait --diff $LOCAL $REMOTE

How can I use VS Code as a git mergetool?

The relevant arguments it needs to accept, I believe, are $LOCAL, $REMOTE, $BASE, and $MERGED.

feature-request git

Most helpful comment

We wouldn't have it any other way. 😉

All 96 comments

Not supported yet.

Is this feature being included in the next iteration, by any chance?

Probably not, this is a big endeavour, since a merge UI needs to be implemented.

Is there any plan for the merge UI to support three-way merging? (e.g. change a, change b, common ancestor)

We wouldn't have it any other way. 😉

Can't upvote this one enough. This is the top scenario for me to fall back to a different editor/IDE (cough* memory-hog Webstorm *cough) :)

If possible, this would be a godsend, due to several reasons:

  1. Meld, although functional, severely lacks in functionality in relation to configurable key-bindings and colour highlighting, and is really _really_ slow to start on my Windows machine, even when installed on an SSD.
  2. I'd like the merge editor to also accept the same .editorconfig/settings which my main text editor has, and if vscode does fill that gap, it'd be awesome.
  3. On smaller levels, the editor theme and familiarity with the interface is also a plus - sometimes I or my team makes mistakes while merging due to no syntax highlighting, which although small, have caused huge bugs in production systems. And some of those mistakes are rather difficult to even fathom until they occur. _I guess there would always be similar problems with mergetools_, but perhaps they will be reduced if one could merge in the same environment in which one writes.

Like I said, meld is _ok_, but it'd be super if vscode would some day be used in that scenario.

Visual Studio was always my code merger of choice. Would love to see this feature!

No problem on using other git mergetool but really would like to see own merge UI happen really soon!!

😐 meh.

I expect these features in heavy weight IDEs. In vscode's class of light weight editors (in which I'd consider atom, sublime, etc) I don't. For git-related activities I favor a terminal and vim for conflict resolution. The GUI crowd already has great uni-taskers like meld, diffmerge, kaleidoscope, etc.

@kumarharsh that's a good point about immediate feedback (e.g.; linting.) Going the vim route above, I suppose you can set git's default external editor to vscode... tho could be a pain to provide context to the project-specific linting/syntax/etc rules.

+1

can this feature be implemented as an extension of vscode? or any exists ext recommended.

I dont think so, as i can see extesions are not allowed to create ui features

Enviado do meu telefone Windows 10

De: Tank Sui
Enviado:quarta-feira, 7 de dezembro de 2016 10:41
Para: Microsoft/vscode
Cc:Herbert Pimentel; Comment
Assunto: Re: [Microsoft/vscode] Using VS Code as a git mergetool (#5770)

can this feature be implemented as an extension of vscode? or any exists ext recommended.

You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

The plugin can provide UI features: look at Git History. It renders a webview, which can "potentially" be used as a merge-tool. But I think it'll be very hard for a plugin to do it without some level of support by vscode itself.

Main issue with kaleidoscope, meld, etc tools is in very typical use-case:
Edit result during merge. Like, you know: accept this line from the left, accept that line from the right, and also, add this small fix so they both can work together.
Captain obvious is reporting: Merge tools are good in merging :D
But editing using i.e meld is totally pain especially when you are get used to such handy tool as vscode. That's why most developers want merge-tool integrated in their editor.

allowing us to see the diff (incredibly useful features in an editor) but not giving us a way to merge is very underwhelming

A VS Code extension would be perfect for merging conflicts.

+1

Git side by side conflict resolver not working in latest VS code.

Version 1.10.2
Commit 8076a19fdcab7e1fc1707952d652f0bb6c6db331
Date 2017-03-08T14:02:52.799Z
Shell 1.4.6
Renderer 53.0.2785.143
Node 6.5.0

Would really like to be able to edit code while merging while using my code editor (vscode), rather than having to use some other editor.

This is a "Must Have" feature to be able to completely move to VSCode when you work in Agile Development Projects. An integrated merge tool is a huge timesaver without that the git feature is just incomplete. I hope we can have this soon.

+1

i need mergetool

I can recommend "better merge" extension for now...

Yes, that's what I am using it now, and pretty ok!

Hence, this issue I think can be closed?
On Sun, 30 Apr 2017 at 4:58 PM, Ali Robertson notifications@github.com
wrote:

I can recommend "better merge" extension for now...


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/Microsoft/vscode/issues/5770#issuecomment-298222866,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAU8Q2JVio1PlIvEb8S1zg2cf5tzxxciks5r1Fs9gaJpZM4IPCMA
.

>

Sent from iPhone

@alirobe better merge haven't a three version windows like meld
Seems like vsc just have three window,but no anyone implement a merge tool ?

Hi @nchammas, @joaomoreno and all you other interested folks,
Today I setup using VS Code as my git mergetool and explained it over on StackOverflow: How to use Visual Studio Code as Default Editor for Git MergeTool (it explains it with more detail, so check it out!).

Here is the speed version:
You can edit your .gitconfig directly and paste in

[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = code --wait $MERGED

or from the command line enter

  1. git config --global merge.tool vscode
  2. git config --global mergetool.vscode.cmd "code --wait $MERGED"

Then use git mergetool from within the git directory with the merge conflict, and ta-da 😄!

You should see a line that says Accept Current Change | Accept incoming Change | Accept Both Changes | Compare Changes at the spot where the change in question is located.

Just make sure to save your file before closing VS Code!

I like that it has the code lens "Accept Current Change | Accept incoming Change | Accpept Both Changes | Compare Changes", and I love the side by side diff when you click "Compare Changes", but it doesn't let me edit anything in line, or with like a third combined panel that you see in Visual Studio's merge tool or other tools like Meld, Winmerge, or Beyond Compare. I would love to see that third panel in the side by side comparison so that I can do more custom merging.

@jaxspades, FWIW, what I do when I need to do custom is Accept Both and then edit. So far that's worked well enough, though I've had no particularly hairy merges using this yet.

The "real" Visual Studio acts as a great merge tool, FWIW. I'd love to see that feature in VS Code.

+1 to @zneak

The current take this block or that block is terrible and is wasting a lot of time, refactoring, and errors. I would love to have the ability to pick line by line like VS.

False positives on file changes are an issue as well when bouncing around branches.

I love the tool, this area is just lacking.

Hello
in VScode need to be default merge tool.
We have cool diff-tool, and vsc can divide to three parts, so.. need just implement it.
We could be implement it by community with ext, but we not allowed to change UI. We cannon build custom buttons in ui, so help us

I use kdiff3 on Windows and Mac as my default git mergetool. It has 4-view 3-way merge, very good auto-resolution, and it's free & cross-platform.

In May, better merge was integrated. This effectively solved the issue by adding a merge UI.
https://code.visualstudio.com/updates/v1_13

Ericop has provided instructions on configuring vscode to use the 'better merge' interface as a mergetool above.

This issue should therefore be closed, resolved.

@alirobe I don't think this merge is good,maybe it can seems like meld,three editor show LOCAL,BASE,REMOTE

@zjjott understandable, I would suggest opening a new issue requesting specific enhancement to the existing feature, and referencing that here.

This is one of the best extension I've ever used https://marketplace.visualstudio.com/items?itemName=letmaik.git-tree-compare#review-details

@joaomoreno Following on your comment are we going to see 3 way merge in the future?

@zjjott kdiff3 does this really well (Local, base, remote, and result views). I'm really not sure why folks need/desire extra functionality in vscode when this existing cross-platform tool is already so great.

@RoyTinker because i'm usually don't do just 'merge'. You have to edit something (when some conflicts occurs) and when you edit something you want you best-ever-editor, not something which kdiff3 has (its ok but vscode is way much better)

Why don't you talk with @eamodio and import his awesome work on GitLens for VSCode?
I'm extremely pleased with it, especially when browsing conflicted file, when I have changes from both streams in one view, and can accept current change, incoming change, both changes or even edit them in one go.
It's pretty close to ideal, only sometimes it goes nuts with line endings on Windows, then there's only full Visual Studio to the rescue.
Otherwise, best git GUI experience from IDE I've ever had.

@m-wilczynski While I really appreciate the kind words -- the merge conflict support isn't part of GitLens -- it is built directly into vscode itself (it was originally another extension that was brought into core)

@eamodio - sry, didn't know. 😄 Doesn't change the fact, that for me (and most of my colleagues that use VSCode @ work due to my recommendation) VS Code is useless for working with git without GitLens.
With GitLens I'm eager to open VSCode up even if I'm not coding in it atm (mostly using it for TypeScript and JavaScript) just to see clearly wth is going on in this merge.
It's all about user experience.
Even if VSCode had it all included and you only needed to visualize it properly - you're the one to blame for my awesome user experience. 😉

@m-wilczynski Very humbled. Thank you — I greatly appreciate the kind words!

It's coming up on two years now... and imho this is still one of the most obvious missing features at this point. would love to make VSCode my mergetool.

@tracker1 This issue is technically solved: https://github.com/Microsoft/vscode/issues/5770#issuecomment-308533904. I don't know why it still hasn't been closed.

@joaomoreno can this issue be closed?

I think the reason it's still open (and also why I'm still watching it) is people are looking for a side-by-side three way merging capability in vscode. For example, I currently use meld (example screenshot).

Yes and we have scenarios when git have Conflict(rename/rename) and $MERGED file comes in blank and stil necessary edit making diff $LOCAL $REMOTE command, i using this cmd below for this problem

code --wait --diff $REMOTE $LOCAL | cp $LOCAL $MERGED

But those can be made into separate issues - the primary job of this this particular issue is done IMO.

Maybe what's shown in #5770 works fine for tiny changes, however it is a poor experience for large changes and you really need a 3 or 4 pane experience to do this properly.

I currently use Visual Studio (proper) as the MERGE/DIFF tool and MELD when Visual Studio (proper) is not installed. These get the job done, but it would be great to be able to edit the code with the same tool that was used to write it in the first palace.

If they want to close it, that's fine, as it _can_ be used as a merge tool, but then we should have an issue immediately created to capture the side by side three way diffing capability.

Now vscode has the option to have more than two windows visible. (as of v1.24.0). I have not tried a 3 way merge myself but it should certainly be a possibility now

This is the biggest shortcoming of this amazing editor for sure

Three-way merge is a must. The current way of performing git merge is very crude at use.

Please add three way merge

@michaelKurowski Yeah recently I heard colleagues complaining about VScode merging capabilities, didn't dive in the details though. So in short if this aspect can be improved, it would do good for vscode.

Please add three way merge

I'm not sure I completely understand. People here seem to be asking for three-way merge, but it seems like VSCode already has a three-way merge, as in this screenshot.

image

However, as I understand it, there's no way to invoke the three-way merge from the command line. As the initial posting mentioned, this would involve a way to invoke with four arguments on the command line: the base file, the two different revised versions, and the path to write the final merged result.

In my case I'm wanting to use VSCode as a merge tool with Perforce and not Git, but assuming VSCode accepted these four filenames on the command line then it wouldn't really matter which source control software you are using, the concept of merging is the same.

Should this issue be called something like "Add command line option for invoking the existing 3-way merge functionality", or is there something that I'm misunderstanding about the current merge implementation in VSCode, besides lacking command line usage, that makes it unsuitable for git three way merges?

I'm not sure I completely understand. People here seem to be asking for three-way merge, but it seems like VSCode already has a three-way merge, as in this screenshot.

image

However, as I understand it, there's no way to invoke the three-way merge from the command line. As the initial posting mentioned, this would involve a way to invoke with four arguments on the command line: the base file, the two different revised versions, and the path to write the final merged result.

In my case I'm wanting to use VSCode as a merge tool with Perforce and not Git, but assuming VSCode accepted these four filenames on the command line then it wouldn't really matter which source control software you are using, the concept of merging is the same.

Should this issue be called something like "Add command line option for invoking the existing 3-way merge functionality", or is there something that I'm misunderstanding about the current merge implementation in VSCode, besides lacking command line usage, that makes it unsuitable for git three way merges?

I believe that they'd like to see something like this:
https://user-images.githubusercontent.com/1470309/32250860-c677e4ce-bec0-11e7-82b5-0196d981cc28.png

@michaelKurowski I see. Perhaps there are two distinct issues then,

  • The visualization of three-way merges. (the current implementation displays merges inline, whereas some people are asking for a three-column view)
  • The ability to use VSCode as a 3-way merge tool invoked from the command line. (which would require a command line option similar to the current --diff file1 file2 but with merge support, e.g. --merge basefile revision1file revision2file mergedfile

My impression is that the original poster was asking for something more like the latter (which seems easy to implement using the current visualization) whereas the request for a three-column visualization of merging is a bit more of a complicated and open-ended request and perhaps the confusion between those two separate requests is causing this issue to get punted?

Ok thanks for clarification @uglycoyote & @michaelKurowski, so in your opinion should we create a new issue/feature-request dedicated to three columns diff view?

It would be good if @joaomoreno could comment on @JeanPerriault's question and my suggestion about whether this issue should be split in two, as he seems to be on the VSCode team. But judging by his previous responses of "a merge UI needs to be implemented" and "we wouldn't have it any other way (than a three-way merge)", it seems like he is seeing both of the issues I was mentioning as one thing.

@joaomoreno, would it not make sense to first, in the short term, implement a command line option to expose the existing merge behaviour? I personally would be fine with using the current inline merging and don't find a 3-column view to be essential (though it might be nice). But if hooking the existing merge up to the command line is an easy task then I would not want it to get stalled indefinitely by the lack of will for the VSCode team to implement a fancier 3-way merge visualization.

yes, give us a visual merge view/editor like http://meldmerge.org/

WinMerge working like a boss
after-3way-merge

yes, give us a visual merge view/editor like http://meldmerge.org/

I use Meld and while I would like to see VSCode does the same I don't see a problem in using Meld for this, honestly.

@lig why then I have to use vscode for editing? I can just use notepad

@josser just use whatever tool fits your current task better. I think this holy war is offtopic btw.

@lig I'm just want to explain why people asking to integrate merge tool into vscode
Because they like vscode and don't like other tools. Merging is also editing. And you want edit files in your lovely editor even if editing is part of merge process

Take a look at this comment: https://github.com/Microsoft/vscode/issues/5770#issuecomment-265497516

@josser like mentioned earlier in this thread many many times, the original ask can be done by setting up git to use VSCode as a mergetool and running git mergetool during conflicts, which opens up the VSCode merging flow that is working fine for me and other users.

If you would like to see a Meld-like interface when using VSCode as a mergetool, _please create a separate feature request in a separate issue_ so that we can stop spamming this thread for what is essentially _an unrelated feature request_.

@lig I'm just want to explain why people asking to integrate merge tool into vscode
Because they like vscode and don't like other tools. Merging is also editing. And you want edit files in your lovely editor even if editing is part of merge process

Take a look at this comment: #5770 (comment)

Plain and easy ! That's exactly what people want. Why is that so hard to understand ? I start a diff and the next step is merging. It belongs together and any separation is totally against a good workflow and just costs time. I want to use the visual studio code editor and no external tool.

I would like also to have VS Code to be usable as a three way merge editor. Accept or decline changes from left or from right and modify the result before commiting the changes. This would improve VSCode so much. It really makes no sense to use that many powerful git features except one of the important ones: the merge.

Make it JetBrains like. (https://github.com/Microsoft/vscode/issues/37350)

And honestly, the meld merge looks pretty ugly. This is from 2012, right? And it looks like it is from 2003. Why should I time-travel each time I wanna do the 3 way merge?

A new issue has been created to have the three-way merge views: https://github.com/Microsoft/vscode/issues/37350

Someone took the time to open a separate issue for three way merge UI (as recommended here) complete with beautiful mock-up, only to have it closed immediately. =(

@mofahead it looks like the one I created was a duplicate of #37350 .. though the close mentioned this issue.

It would be nice to have the https://github.com/Microsoft/vscode/issues/8226 improved before enabling it as a merge editor

Hi everybody!

You can follow the tutorial to config VSCode as an official git.mergetool:

https://stackoverflow.com/a/44549734

It seems like there is some confusion here with people mentioning both UI aspects and merge functionality. For me, the biggest productivity killer today in VSCode is that fact that merge works vertically instead of side by side.

I honestly don't understand how this can even be remotely considered an acceptable UI for this functionality. Useless.

For those with a Mac, here's a workaround.

  • Install Diffmerge
  • Install VSCode Git Diff and Merge Tool
  • Edit ~/.gitconfig
    add
[diff]
        tool = diffmerge
[difftool "diffmerge"]
        cmd = diffmerge \"$LOCAL\" \"$REMOTE\"
[merge]
        tool = diffmerge
[mergetool "diffmerge"]
        cmd = diffmerge -merge \"$LOCAL\" \"$BASE\" \"$REMOTE\"
        trustexitcode = true
        keepbackup = false
  • In VSCode, go to Source Control, right click the file and select Launch merge tool

The only thing is, I can't get the files to automatically merge back to VSCode in all scenarios.

Have been using diffmerge for many years on Mac and Windows. Switched to Sublime Merge couple of months ago. I really, really love it. It’s fast, it’s modern. I use it on Windows also instead of Visual Studio when I need to work in that environment.

back to emacs for diff and merge of non-VCS controlled directories :(

VS Code has a nice plugin L13D for comparing directories (e.g. config directories between a source and dest computer), but you can't merge without git or some other version control.

So, it's emacs' diff-directories to make a session and then merge in what I want selectively, for this task. I'm trying to leave emacs, but I still find the occasional thing it can do which Code can't.

VS Code has a nice plugin L13D for comparing directories (e.g. config directories between a source and dest computer), but you can't merge without git or some other version control.

Do you have a link to L13D?

I'm not sure I completely understand. People here seem to be asking for three-way merge, but it seems like VSCode already has a three-way merge, as in this screenshot.

image

This works for completely trivial merge conflicts, but I'm encountering people at companies who only use VSCode and their entire idea of "merge conflicts" is based on VSCode's grossly oversimplified diff. And when they get a non-trivial merge conflict, they're always "picking one side" (basically dropping somebody's changes in a few lines instead of combining them) at least once.

We need a meld-like interface in VSCode not just because it's cool, but because without it we're encouraging bad practices in younger devs.

It's not just "younger devs". I've been coding for 20 years and a 3-pane merge is just outright better. You will make mistakes with an inline diff that you would have caught if you could see the entirety of each version of the code at once.

I would like to see three panes with diffs against the base commit in each pane. That would make it easy to see what has changed where and what changes to keep and not.

@lig I'm just want to explain why people asking to integrate merge tool into vscode
Because they like vscode and don't like other tools. Merging is also editing. And you want edit files in your lovely editor even if editing is part of merge process

Because VSCode is more than a glorified text editor. It is an IDE with linter and intellisense. It even parses my Python code for undefined variables. And I find it very useful when merging to be able to see, in real-time, the hints that the linter+intellisense+etc. offers when I choose which lines to accept.

Using a "dumb" merge-tool makes it harder to find mistakes in the merge and even correct it after merging and going back to VSC.

This one of just the 2 or 3 things keeping me from coming back to VS Code

This is in the 2020 roadmap-

Provide full merge support (3-way)

See- https://github.com/microsoft/vscode/wiki/Roadmap#scm

I just released my extension VS Code as Git Mergetool. It is not as feature-rich as other merge conflict editors but should be usable. As default I configured a 4-pane layout which I found more practical than the classical 3-column layout. Watching out for feedback!

It’s not available in the Marketplace yet so you need to download it from GitHub and install it manually. That should change in a few days. _It is now available on the Marketplace._

Hello @zawys,

Does it support comparing the 3 or 4 folders that I will merge the oprhan files?

Hi @gusbemacbe,

In its current state, the extension was primarily thought as "3-way" file merge tool fitting into the interface of git mergetool. This is still the primary goal. However, I'm planning to extend the functionality so that no git-mergetool process needs to be running as that little shell script has some own UX deficiencies. Instead, I want to integrate the extension more with VS Code.

In that process, I will clone some of the functionality of git-mergetool, e.g. resolving delete and symbolic link merge conflicts. I'm not sure how far that covers your use case. Maybe I could also add e.g. an accept-all-incoming-in-folder command. Please open an issue for
the extension to discuss further.

My extension can now be found on the Marketplace.

My extension can now be found on the Marketplace.

202010-04_0859_27__

@InLaw You need to update your VS Code to use the extension. For further discussion, please create a bug report on the extension's site.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

biij5698 picture biij5698  ·  3Comments

omidgolparvar picture omidgolparvar  ·  3Comments

lukehoban picture lukehoban  ·  3Comments

curtw picture curtw  ·  3Comments

mrkiley picture mrkiley  ·  3Comments