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

GitVisual Studio-CodeMeld

Git Problem Overview


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?

Git Solutions


Solution 1 - Git

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

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

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

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.

Solution 5 - Git

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:

Solution 6 - Git

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionUsmanView Question on Stackoverflow
Solution 1 - GitLuís Henrique FariaView Answer on Stackoverflow
Solution 2 - GitbilabilaView Answer on Stackoverflow
Solution 3 - GitmimoView Answer on Stackoverflow
Solution 4 - GitbarshopenView Answer on Stackoverflow
Solution 5 - GitRahulView Answer on Stackoverflow
Solution 6 - GitJohnny5View Answer on Stackoverflow