在 Visual Studio Code 中,左侧有一个 Git 图标,长这样:
点击这个图标,然后双击 Changes 下列出的任意一个文件,就可以看到两边的 Git 差异。
如果您想查看来自不同分支的差异更改,需要进行一些额外的工作。例如,您想要查看在您的功能分支中最近N个提交中的所有更改。
通过将以下内容添加到~/.gitconfig文件中,设置Visual Studio Code为默认difftool。
[diff]
tool = vscode
[difftool "vscode"]
cmd = code --wait --diff $LOCAL $REMOTE
前往你的Git项目。键入:
git difftool {{你想要检查的分支名称}}, 例如 git difftool master
对于每个文件,将提示是否要在Visual Studio Code中打开它。
code --diff file1.txt file2.txt
。 - Ryan Norooz|
和命令 code -
连用只能实现一次性使用。例如:git diff some_tag_or_branch | code -
- Jacob Phillips你可以在Visual Studio Code中实现这个功能,具体步骤如下:
CTRL+P
,然后按>
,然后键入“Settings”,菜单就会滚动下来,我会寻找UI菜单选项。 - GabrieliusCTRL+,
- Giulio在 Visual Studio Code 中打开文件 ~/.gitconfig
:
code ~/.gitconfig
复制以下行到~/.gitconfig
文件中:
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
保存更改。通过运行 Ctrl + Shift + ` 打开 Visual Studio Code 中的终端。在终端中运行以下命令:
git difftool master origin/master
现在可以使用“三个点”按钮来切换内联视图。
microsoft/vscode
issue 123111:允许条件性的侧边对比或内联diffEditor。
这个问题已经通过PR 189304解决,并且已经包含在VSCode 1.82中(2023年8月)。我喜欢侧边对比。我对内联对比也很满意。
我不喜欢的是在狭窄的编辑器窗口中查看侧边对比:
如果差异编辑器的宽度太小,编辑器会自动切换到内联视图。
如果编辑器再次足够宽,之前的布局将恢复。
设置 "diffEditor.useInlineViewWhenSpaceIsLimited": false
来禁用此行为。
diffEditor.useInlineViewWhenSpaceIsLimited": false
对我很有帮助! - undefined
ctrl-shift-G
。 - Out of Control⌘K V
打开预览,如 VSCode keybindings 中所述。 - Michael Behrens