In the git submission process, there are three parts: working tree, index file, commit
Of these three parts:
working tree: It is the directory where you are working. Whenever you make changes in the code, the state of the working tree changes.
Index file: It is the index file, which is the bridge connecting the working tree and the commit. Whenever we use the git-add command to register, the content of the index file changes, and the index file is synchronized with the working tree.
Commit: It is the final stage. Only after committing, does our code really enter the git repository. We use git-commit to submit the contents of the index file to commit.
in conclusion:
git diff: is to see the difference between the working tree and the index file.
git diff --cached: is to view the difference between index file and commit.
git diff HEAD: is to view the difference between working tree and commit. (You must not forget that HEAD represents the information of the latest commit)