4 Exploring History (git diff & show)

4.1 Difference between current file and N commit ago (git diff HEAD)

Let’s add another line to foo.txt

Check what is different from your current version of foo.txt compared to the last commit

## diff --git a/foo.txt b/foo.txt
## index ce01362..94954ab 100644
## --- a/foo.txt
## +++ b/foo.txt
## @@ -1 +1,2 @@
##  hello
## +world

You see that “world” is preceded by a plus sign, indicating it is an insertion.

Check difference compared to two commits ago

## diff --git a/foo.txt b/foo.txt
## index e69de29..94954ab 100644
## --- a/foo.txt
## +++ b/foo.txt
## @@ -0,0 +1,2 @@
## +hello
## +world

You can check difference between the current file against a specific commit based on its identifer (the unique identifier is different for you, use git log to check!)

4.2 What was done in ____ commit? (git show)

Sometimes we want to check what was done during a certain commit (instead of comparing differences)

## commit c9513216e0846661489ec28432b591429fd41c8e
## Author: Shady Whale <shadywhale@allthewhales.com>
## Date:   Mon Sep 30 23:57:50 2019 +0000
## 
##     Add foo.txt to repo
## 
## diff --git a/foo.txt b/foo.txt
## new file mode 100644
## index 0000000..e69de29

You have now compared different versions of a file using git diff and check its changes during a specific commit using git show.