使用VS Code作为git diff工具

问题描述

VS代码具有很好的内置功能,可以区分两个文件

是否可以将vs代码 diff 用作git的 diff 工具?

解决方法

是的,可能 您只需将Visual Studio Code设置为默认的difftool,只需将它添加到〜/ .gitconfig文件中即可。

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

此操作之后,只需运行命令,例如:git difftool master,几秒钟后VS Code运行difftool

,

Maciej所说,gitconfig是必经之路。这样,我不仅可以将其设置为difftool,而且还可以将其设置为git的合并工具。

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

我使用VSCode Insiders提前获取最新(但仍稳定)的功能

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