Use VS Code as git diff tool

Viewed 5995

VS code has nice inbuilt feature to diff two files.

Is it possible to use vs code diff as the diff tool for git?

2 Answers

Like Maciej says, gitconfig is the way to go. With this I can set it up to be not just a difftool, but also the merge tool for git.

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

I use VSCode Insiders, to get the latest (but still stable) features ahead of time

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

Edit: There is now official VSCode Documentation for this.

In your ~/.gitconfig file:

[merge]
  tool = code
[mergetool "code"]
  cmd = code --wait --merge $REMOTE $LOCAL $BASE $MERGED

Yes, its possible You just must set up Visual Studio Code as your default difftool by adding this in your ~/.gitconfig file.

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

Aftrer this operation, just run command for example: git difftool master, after few second VS Code run difftool

Related