There are 3 main git diff versions:
git diff- difference between WORKING DIRECTORY & STAGEgit diff --staged- difference between HEAD & STAGEgit diff HEAD- difference between HEAD & WORKING DIRECTORY
Above are the definitions I found almost at every place from various people over the net
I performed certain commits on 3 files in the following order:
ce6f5bb (HEAD -> master) 6th commit, file1 c1c67da 5th commit, file3 ea51776 4th commit, file1 file2 001675b 3rd commit, file1 file2 ec04f53 2nd commit, file2 21cb6c1 1st commit, file1a. file2 modified in working direcory
b. Nothing STAGED for commit
c. file1 & file3 not modified
My Queries are:
1. git diff
git diff
diff --git a/file2.txt b/file2.txt
index 21106bf..c755a1e 100644
--- a/file2.txt
+++ b/file2.txt
@@ -1,3 +1,4 @@
123
345
678
+90.
Even though STAGING AREA WAS EMPTY, why diff was shown?
2. git diff HEAD
git diff
diff --git a/file2.txt b/file2.txt
index 21106bf..c755a1e 100644
--- a/file2.txt
+++ b/file2.txt
@@ -1,3 +1,4 @@
123
345
678
+90.
if LAST COMMIT (HEAD) was related to file1, then why diff of file2 is shown?
HEAD doesn't contain anything related to file2 at all
NOW AFTER STAGING file2 :
3. git diff
It does not show anything!
(I assume it will only show diff if a file is Staged as well as some changes apart from staged version are made in Working Directory too)
Well if that is the case, then why diff was shown in 1.
4. git diff --staged
git diff
diff --git a/file2.txt b/file2.txt
index 21106bf..c755a1e 100644
--- a/file2.txt
+++ b/file2.txt
@@ -1,3 +1,4 @@
123
345
678
+90.
again if HEAD is pointing to file1, then why diff of file2 is shown?
I CREATED THIS IMAGE BELOW (Note: ANOTHER SCENARIO. Not same as above):
for git diff HEAD, My guess is that for every TRACKED FILE, HEAD will keep traveling backward until it finds the LATEST VERSION OF THAT FILE which was committed, to compare against the one in Working Directory
If we consider a new scenario as below, then for git diff HEAD, is it like below what I have assumed?
