For example, I create a new file called test.html in the workspace, and then git status:
git detects this newly added file and prompts to add it temporarily through add. storage area.
Execute the following:
git reset --hard
It seems that nothing is executed. Look at the git status:
It is still the git status when the file was just added. Tip, the newly added test.html has not been deleted.
Now execute:
git add dist/test.html
View git status:
Put the newly added test.html into the temporary storage area and execute the following:
git reset --hard
Looking at the git status again, the workspace and staging area are all clean, and the newly added test.html is gone.
Summarize the difference between the two operations:
Also create a new test.html file
The first is to directly git reset --hard, create a new The test.html file is retained in the workspace
The second method is to add this new test.html file first, add it to the temporary storage area, and then git reset --hard, the test.html file in the workspace is also deleted.
If git reset --hard overwrites the workspace and staging area with the last submitted record, then in the first case, test.html should be deleted. If git reset --hard does not process untracked files, in the second case, test.html will not be deleted in the workspace.
I am already dizzy and waiting for git to answer. I think this is probably a bug in git.
git reset --hard is to reset the contents of the staging area and workspace to the version pointed to by HEAD.
So in the second case, the test.html in your staging area and work area is gone.
As for the first case, if you look carefully at the first picture, it shows that test.html is an Untracked file, which means that the file has not been tracked, so of course it will not be deleted.
git reset
It affects the Stage and Working areas (you said it yourself), so it’s not that Git has a bug, but that you don’t understand the basic concepts.1. To undo the temporary storage area, use git reset. Do not try --hard.
2. To undo the workspace, use git checkout.