首页 > 解决方案 > 使用 vscode 作为 git 版本 (2.31.1) difftool

问题描述

我安装了 git 版本 2.31.1.windows.1 并按照所有 git 中显示的所有必要步骤逐步尝试使用 VSCode 作为我的主要 difftool,我将这些行放在 gitconfig 文件中:

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

使用以下步骤:

  1. git config --global diff.tool vscode
  2. git config --global difftool.vscode.cmd "code --wait --diff $LOCAL $REMOTE"

甚至在 Windows 中将 VSCode 添加到PATH中,虽然我在运行时打开 VSCode 没有问题git config --global -e,但是当我输入命令时git difftool没有任何反应,它只是开始一个新行。

标签: gitvisual-studio-codedifftool

解决方案


如果没有要显示的差异,git difftool则不会打开任何东西——就像git diff返回而不输出任何行一样。


git diff/有一个已知的陷阱:没有进一步的参数,它显示暂存的内容与磁盘上的文件git difftool之间的差异;如果您的所有更改都已暂存(ed ),则不会显示任何内容。git add

如果要查看与当前存储库状态相比暂存的更改,请运行:

git diff --cached
# or :
git difftool --cached

额外说明:一个有用的选项git difftool-d

git difftool -d --cached
git difftool -d <branch1> <branch2>
git difftool -d <anything that can get compared ...>

它不是一个一个打开文件,而是以“目录差异”模式打开您的差异查看器。


推荐阅读