I have much confusion about staging area. firstly, Git Gud: The Working Tree, Staging Area, and Local Repo tell me the staging area will be empty after git commit,on this way, git commit maybe move files to local branch rather than copy.
But it seemed this cant explain this practice:git reset --soft HEAD~ modifies staged snapshot?. git reset --soft HEAD^ after git commit, and then git status, it seemed there exist difference between staging area and HEAD^, and the difference is the files which has been committed after HEAD^. On this way, it seemed that staging area is not empty after git commit, or rather how to explain the difference between current HEAD and staging area if staging area is empty?
And another question is that the command
git diff --cached
which used to compare the difference between staging area and HEAD. And What does 'stage' mean in git? tell me staging area only store the file change. For example we git clone a project which has three files:a.txt b.txt c.txt,and we modified c.txt and git add it. Then we execute command git diff --cached. Now the local branch has three files and staging area has only one files. why it only show the change of c.txt not included the information that staging area dont has a.txt b.txt compared with local branch.
In a word, I have two question:
1. what happend when git commit, move or copy file from staging area to local branch?
2. what happend when git diff --cached? just compare files which staging area contains?
reference:
A commit is simply a checkpoint telling git to track all changes that have occurred up to this point using our last commit as a comparison. After committing, your Staging Area will be empty. from Git Gud: The Working Tree, Staging Area, and Local Repo