如何在 Visual Studio Code 并排文件上看到“git diff”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/51316233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can I see 'git diff' on the Visual Studio Code side-by-side file?
提问by Ricardo Jesus Jarquin Perez
I would like to know how to see as a file with the command git diff master origin/master
in the terminal on Visual Studio Code.
我想知道如何git diff master origin/master
在 Visual Studio Code 的终端中使用命令查看文件。
I did a git fetch
from my remote repository, and now I want to see the diff, but with the command just show me in the terminal.
我git fetch
从我的远程存储库做了一个,现在我想查看差异,但是使用命令只在终端中显示我。
Example of what I want:
我想要的例子:
回答by Ratan Uday Kumar
In Visual Studio Code, on the left side, there is a Git icon that looks like this:
在 Visual Studio Code 中,左侧有一个 Git 图标,如下所示:
By clicking on this icon, you can see the Git difference in two sides.
通过点击这个图标,你可以看到两个方面的 Git 差异。
回答by Boncho Valkov
If you want to see the diff changesfrom different branches, there is some extra work. For example you want to see all the changes from last Ncommits in your Feature branch.
如果你想看到的差异变化,从不同的分支,有一些额外的工作。例如,您想查看Feature 分支中最近N 次提交的所有更改。
Set up Visual Studio Code to be your default difftool by adding this in your ~/.gitconfigfile.
[diff] tool = vscode [difftool "vscode"] cmd = code --wait --diff $LOCAL $REMOTE
Go to your Git project. Type in:
git difftool {{branch you want to check with}}, for example git difftool master
You will be prompted for each file, if you want to open it in Visual Studio Code or not.
通过在~/.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 中打开它,系统将提示您输入每个文件。
回答by lboyel
You can achieve this in Visual Studio Code by
您可以通过以下方式在 Visual Studio Code 中实现此目的
- Opening up settings (On window/linux File > Preferences > Setting. On macOS Code > Preferences > Settings)
- Search for diff
- The specific setting is Diff Editor:RenderSide by Side. Mark the checkbox.
- 打开设置(在window/linux File > Preferences > Setting。在macOS Code > Preferences > Settings)
- 搜索差异
- 具体设置为Diff Editor:RenderSide by Side。标记复选框。
回答by billygarrison
Here's a simple way to view your changes since last commit (on current branch):
这是查看自上次提交(在当前分支上)以来所做更改的简单方法:
- Click Git icon on left side of VS Code
- If you've made changes to the file(s) since last commit, you'll see the file(s) listed under "CHANGES"
- Right click the file name (under "CHANGES") and click "Open Changes"
- This will open the two versions of the file side by side with the changes highlighted
- 单击 VS Code 左侧的 Git 图标
- 如果您自上次提交以来对文件进行了更改,您将看到“更改”下列出的文件
- 右键单击文件名(在“更改”下),然后单击“打开更改”
- 这将并排打开文件的两个版本,并突出显示更改
回答by Nitin Bisht
You can diff
any two files by first right clicking on a file in the EXPLORERor OPEN EDITORSlist and selecting Select for Compareand then right-click on the second file to compare with and select Compare with <file_name_you_chose>.
您可以diff
通过首先右键单击EXPLORER或OPEN EDITORS列表中的文件并选择Select for Compare,然后右键单击要与之比较的第二个文件并选择Compare with <file_name_you_chose>来选择任意两个文件。
Alternatively from the keyboard hit Ctrl+ Shift+ Pand select menu File→ Compare Active File With...and you will be presented with a list of recent files. Example:
或者从键盘点击Ctrl+ Shift+P并选择菜单文件→将活动文件与...比较,您将看到最近文件的列表。例子:
回答by Abdollah
Open file ~/.gitconfig
in Visual Studio Code:
~/.gitconfig
在 Visual Studio Code 中打开文件:
code ~/.gitconfig
Copy the following lines in ~/.gitconfig
:
复制以下几行~/.gitconfig
:
[diff]
tool = default-difftool
[difftool "default-difftool"]
cmd = code --wait --diff $LOCAL $REMOTE
Save the changes. Open a terminal in Visual Studio Code by running Ctrl+ Shift+ `. Run the following command in the terminal:
保存更改。通过运行Ctrl+ Shift+ `在 Visual Studio Code 中打开一个终端。在终端中运行以下命令:
git difftool master origin/master
回答by Gomino
回答by adrianvintu
After hours of searching, installing and uninstalling extensions, it seems this is already implemented in VSC.
经过数小时的搜索、安装和卸载扩展,这似乎已经在 VSC 中实现了。
Just click on the top right icon - "Open changes"
And go back to seeing only the file, not the changes, by clicking on the... top right icon - "Open file"
然后通过单击...右上角的图标 - “打开文件”返回仅查看文件,而不查看更改