Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using VSCode, how do I compare two non-consecutive commits on a file in Gitlens

When I use Gitlens in VScode, I cannot find an option to compare commits on a file when they are not consecutive. If I use 'open changes' on a certain commit in the 'File History' panel, it always compares that version of the file with the previous one. Is there a way to choose to compare one revision of the file (and not necessarily the latest revision) with another revision of my choosing of that file?

like image 491
Sean12 Avatar asked Jul 18 '19 05:07

Sean12


People also ask

How do you compare two commits in VS Code?

To compare any two commits in your branch, use the Ctrl key to select the two commits that you want to compare. Then right-click one of them and select Compare Commits. Similar to Commit Details, you can use the Open in New Tab button to open the comparison on a different tab or maximize it on the screen.

How do you compare changes in VS Code?

Tip: You can diff any two files by first right clicking on a file in the Explorer or OPEN EDITORS list and selecting Select for Compare and then right-click on the second file to compare with and select Compare with 'file_name_you_chose'.

How do you compare commits?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

How do I see commit details in VS Code?

When you have repository open in Visual Studio code, you can execute the command Git: View History (git log) from the command Plate. This will open the Git History Window with all change logs for the repository. You can then select individual commits for detailed change logs for each of them.


2 Answers

You can compare two nonconsecutive commits via the following steps (assuming you have the Gitlens extension installed):

  • Source Control tab (or Gitlens tab) -> Open the Branches menu.
  • From the branches menu -> Open the branch of interest.
  • Right click on a particular commit and select "Select for Compare"
  • Similarly, find the other commit you're interested in, right click and select "Compare with Selected"

You will see that under the "Search & Compare" menu, your two different commits are compared.


edit note: you might not see a Gitlens tab anymore as it was (optionally) merged with the Source Control tab, in version 11.2.1.

like image 74
Aaron B. Avatar answered Oct 22 '22 11:10

Aaron B.


  • First, install gitlens plugin
  • Second, press F1, input gitlens:compare references
  • Third, input 1st commit hash and 2nd commit hash

Then, in the right side bar, find SEARCH & COMPARE

You will find the two commits' diff details

Commits' diff details

like image 8
neurobot Avatar answered Oct 22 '22 09:10

neurobot