'Trying to solve merge confilct using Visual Studio Code

I am taking an online course learning Git for the first time. In the course, the instructor is using P4merge as a difftool and mergetool. However, I am using Visual Studio Code. Using Visual Studio Code as a difftool works fine but it won't work as a mergetool. I have been searching all over the web for an answer but no luck.

This is a screenshot of what happens in my terminal when I call mergetool.

Instead of opening Visual Studio Code, it gives me an error.



Solution 1:[1]

Im assuming you added in your gitconfig the following config

[merge]
    tool = vscode
[mergetool "vscode"]
    cmd = code --wait $MERGED
[diff]
    tool = vscode
[difftool "vscode"]
    cmd = code --wait --diff $LOCAL $REMOTE

The error you getting about command not found is because you didn't export the vscode binary to your $PATH. Try to do something like (I'm using Mac)

export PATH=$PATH:/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/

and you should be able to use git mergetool opening in Vscode.

Solution 2:[2]

For MacOS users:

code is not in your PATH, so when git is trying to execute VSCode with the command code it can't find it.
To solve this, open VSCode, open command palette (? + ? + p) , and type:
Shell Command: Install 'code' command in PATH
Than hit enter and give it permissions to install.
This will install code to your PATH and will solve you problem.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fabricio Bedeschi
Solution 2 Yair