Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see difference of first and third commit in git?

I have a problem , I need to see difference of first and third commit in git, but I can see diff of any commit and previous to it.

like image 691
LyndaOlexandr Avatar asked Dec 24 '22 11:12

LyndaOlexandr


2 Answers

git diff [--options] <commit> <commit> [--] [<path>…​]
This is to view the changes between two arbitrary <commit>.

You can get the commit hashes of the 1st and 3rd commit from the log for instance, or you can run it like this (with the relative path to the commits):

 git diff HEAD~1 HEAD~3
like image 50
blas3nik Avatar answered Jan 04 '23 08:01

blas3nik


There is a great GUI tool that will allow you to compare any 2 commits called Git Extensions. Info/download can be found here: https://gitextensions.github.io/.

All you have to do is select the repository you want to look at and Git Extensions will show you the entire commit history across all branches that you are tracking. Just click on the earlier commit, then use CTRL+click on the commit you want to compare to, then in the window at the bottom left of the screen select the "Diff" tab and you can see all diffs across all files in the Repository.

Image is included for reference: Git Extensions GUI example

This is a little more versatile than Git Bash to look at individual file diffs in one window and allow you to switch between files easily. It is available on Windows and Linux though I have only used it on windows.

like image 38
Steven Banks Avatar answered Jan 04 '23 08:01

Steven Banks