Is there a way to see git diff from origin/master using Visual Studio Code?

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?


Solution 1:

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.

Solution 2:

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.

Solution 3:

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

Solution 4:

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.