使用 vscode 作为 git 版本 (2.31.1) difftool

using vscode as git version (2.31.1) difftool

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

[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"

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

如果没有要显示的差异,git difftool 不会打开任何东西 -- 很像 git diff returns 没有输出任何行。


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

如果您想查看与当前回购状态相比的更改,运行:

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 ...>

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