Recently, I started to touch git. Learning to Git diff is always confusing. Git diff compares the difference between the two files. After searching the net on the net, finally found Le answer.
There are two cases, one is when there are files in staging area, and the other is no files in staging area.
(1) When there are no files in staging area, git diff compares the files in the workspace with the files that were last submitted to the repository.
(2) When there are files in staging area, git diff compares the files in the current workspace with those in the staging area.
git diff HEAD-file, compares the differences between the files in the workspace and the files in the repository. Head points to the current version in the repository, and file refers to the files in the current workspace.
Add: The git diff command compares the difference between the current file in the working directory and the staging area snapshot, which is a change that has not been staged since the modification.
Note: Git diff itself only shows changes that have not yet been staged, not all of the changes that have been made since the last commit. So, sometimes after you save all the updated files, you run Git diff and nothing, that's why.
If you want to see what has been staged to be added to the next commit, you can use Git diff--cached or git diff--staged.