Git FAQ: How do I compare two different versions of a file with
This solution depends on what exactly you need to do.
Have not run `git add`
If you just modified a file but haven’t run
git add on it yet, use this:
$ git diff introduction.md
Have run `git add`
To see changes to a file you have run
git add on, but have not committed, use this:
$ git diff --cached introduction.md
In my case, I updated this introduction.md file, and then added it with
git add, so I used that second command:
> git diff --cached introduction.md
diff --git a/_overviews/overview/introduction.md b/_overviews/overview/introduction.md
index eecc4e86..2773a705 100644
@@ -1,6 +1,9 @@
description: This page begins the overview documentation of the Scala 3 language.
+ changes in the last three lines showed the changes I made, so this gave me confirmation that I did what I wanted.
Comparing two file versions in your Git repository
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
As shown on this SO page, there are other ways to issue this Git command, and similar commands.