Search code examples
gitdiffcommitdifference

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.


Solution

  • 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