118

Using Visual Studio Code (version 1.11.2), I can see a side-by-side graphical diff of my current changes very easily by clicking the Source Control button in the left panel. But once I commit those changes to my local repository, I am unable to find a way to see the same side-by-side diff from origin/master.

In other words, is there a way to the spawn comparison tool of Visual Studio Code (version 1.11.2) to show me what I see when I do git diff origin/master, but in the side-by-side graphical diff too?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Uthman
  • 9,251
  • 18
  • 74
  • 104

8 Answers8

121

You can use an extension for this.

Two good options:

Gitlens: https://marketplace.visualstudio.com/items?itemName=eamodio.gitlens

With this one, you can use the >GitLens: Open Changes with... action to compare with any branch (local or remote).

You also can use Git History: https://marketplace.visualstudio.com/items?itemName=donjayamanne.githistory

You can see the entire file history and compare with the current version with the >Git: View File History action.

Georgii Ivankin
  • 2,702
  • 2
  • 23
  • 35
Luís Henrique Faria
  • 1,560
  • 1
  • 11
  • 14
29

From Using Version Control in Visual Studio Code:

Add this to the Git configuration file, like ~/.gitconfig:

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

When using git difftool HEAD HEAD^, Git will ask if to use Visual Studio Code.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
bilabila
  • 973
  • 1
  • 12
  • 18
  • Thanks! Do you know if there is also support for merge? – jurl May 01 '18 at 18:28
  • This is what I am looking for but the change did nothing for me on Version 2.18.0 – HackSlash Jun 28 '18 at 16:51
  • @HackSlash I am on git 2.18.0 too, may be you can see the original doc [Using Version Control in VS Code](https://code.visualstudio.com/docs/editor/versioncontrol#_vs-code-as-git-diff-tool) – bilabila Jun 30 '18 at 03:52
  • 1
    This command does make vscode my default editor. That's cool. Thanks. `git config --global core.editor "code --wait"` – HackSlash Jul 02 '18 at 15:12
12

The accepted answer is good if you want to compare a single file from HEAD to some commit. On the other hand, if you need to diff all your files with another branch, Git Lens also provide solution for that: Go to source control tab on the side(1) > click on BRANCHES(2) > right click on the desired branch (like dev - 3)

enter image description here

Now, a menu will open, choose compare with HEAD

enter image description here

  • You could also do the same with commits, if in phase (2) you'll choose COMMITS instead.
  • You could also use cmnd+shift+p or ctrl+shift+p and type GitLens: Compare HEAD with, and then choose the specific wanted commit/branch.
barshopen
  • 1,190
  • 2
  • 15
  • 28
9

I use GitLens extension as well. Go to Source Control tab, right click on file you want to compare with origin/master (or other) branch. From the menu choose Open Changes with... and pick a branch.

Compare local file changes to master

mimo
  • 6,221
  • 7
  • 42
  • 50
0

I am using vscode with GitLens
The most convenient way to see diff from origin/$branch is to use git merge tool.
For example if I want to compare local and remote develop branch I will use the following command

git merge --no-commit --no-ff origin/develop

And the most exiting thing is that I can see all the changes in all the files from the gitlents extension tab and side by side and in case I don't want to merge there is a command

git merge --abort

Hope it helps someone!

serhii kuzmych
  • 187
  • 3
  • 9
0

In case the you are not in synch with the master branch, and your changes are commited to current branch, do git merge master, note the changes, then remove them with git reset.

Otherwise, if you have already merged the latest changes from master to your current branch, you might want to just use the File history section of the Source Control side panel. The icon highlighted in yellow in the image below opens a side-to-side file compare.

enter image description here

PS: The Git Lens "Open changes with..." is a nice solution, but this is a paid extension, which stops working after trial period.

Murilo Perrone
  • 452
  • 4
  • 7
-4

From MSDN blog

Viewing Diffs

Our Git tooling supports viewing of Diffs within VS Code. Click the file in the Git view to display a side-by-side view. This allows you to compare your current file with a previous version of it:

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
Rahul
  • 1
  • 1
-7

It doesn't use Visual Studio Code, but if you just want to see a quick summary of changes... just start a PR from the branch on GitHub.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Johnny5
  • 463
  • 2
  • 5
  • 16
  • This doesn't work if you want to see diff between staged/uncommitted changes etc, also you have to push each commit just to see the diff – Steel Brain Mar 28 '18 at 22:48