Git: How to compare two different versions of a file

If you’re using Git and need to compare two recent versions of the same file, I can confirm that this git diff command works:

git diff HEAD^ HEAD nodeBlog.scala.html

That command compares the second-most recent version of the file (given by HEAD^) to the most recent version of the file (HEAD). In this example I want to see the detailed differences of these versions of the file named nodeBlog.scala.html. In my case, the result of this command is shown in the image.

Per the excellent book Pro Git, “HEAD^” means, “The parent of HEAD.”

As shown on this SO page, there are other ways to issue this Git command, and similar commands.

Update ('git log' and then 'git diff')

I did the same thing again today, but with some different Git commands. First, I created a short/concise list of all changes to a file using this git log command:

$ git log --pretty=oneline --abbrev-commit divKofiPatreon.scala.html
6f343d4 Changed the Ko-Fi text (Tip Your Barista?) and color to see if it makes a difference.
f73f744 Took the Kofi ad out of the upper-LHS. Also added the RSS icon back to the header.
eb7c0ce moved the text that i put under the Kofi icon into the properties file so i can test things more easily on the server.
3091aaf Got rid of the Patreon logo. Only using KoFi for now. Also changed the KoFi text.
755b10c Changed the text under the Kofi ad.

Once I saw the commit (f73f744) that I wanted to compare the current version of the file (HEAD) to, I ran this command:

$ git diff HEAD f73f744 divKofiPatreon.scala.html 

That showed all of the differences between the two versions of the file, with this difference being the important change I was looking for:

-<script type='text/javascript'>kofiwidget2.init('Tip Your Barista (author)?', '#4299cc', 'N4N31K5N6');kofiwidget2.draw();</script> 
+<script type='text/javascript'>kofiwidget2.init('Buy Me A Coffee!', '#FF5E5B', 'N4N31K5N6');kofiwidget2.draw();</script>

So again, if you need to see how to compare two versions of a file with Git, I hope these examples are helpful.

Photo D8
Git: How to compare two different versions of a file