Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I see 'git diff' on the Visual Studio Code side-by-side file?

People also ask

How do I compare git branches in Visual Studio code?

To add some details on usage, the way I found to compare branches in Git Lens is to; Open the Explorer view (Ctrl + Shift + E), find the Git Lens group, right click the branch you want to compare and select 'Select for Compare',then right click the second branch and select 'Compare with Selected'.

How do I see all git diff?

The diff can be done with git diff (followed by the filename or nothing if you want to see the diff of all modified files). But if you already did something like git add * , you have to undo with git restore --staged .


In Visual Studio Code, on the left side, there is a Git icon that looks like this:

By clicking on this icon, then double-clicking one of the files listed under Changes you can see the Git difference in two sides.


If you want to see the diff changes from different branches, there is some extra work. For example you want to see all the changes from last N commits in your Feature branch.

  1. Set up Visual Studio Code to be your default difftool by adding this in your ~/.gitconfig file.

    [diff]
        tool = vscode
    [difftool "vscode"]
        cmd = code --wait --diff $LOCAL $REMOTE
    
  2. Go to your Git project. Type in:

    git difftool {{branch you want to check with}}, for example git difftool master

  3. You will be prompted for each file, if you want to open it in Visual Studio Code or not.


You can achieve this in Visual Studio Code by

  1. Opening up settings (On window/linux File > Preferences > Setting. On macOS Code > Preferences > Settings)
  2. Search for diff
  3. The specific setting is Diff Editor:Render Side by Side. Mark the checkbox.

After hours of searching, installing and uninstalling extensions, it seems this is already implemented in VSC.

Just click on the top right icon - "Open changes" enter image description here

And go back to seeing only the file, not the changes, by clicking on the... top right icon - "Open file"

enter image description here