A strange git problem, please help me analyze it?
我想大声告诉你
我想大声告诉你 2017-05-02 09:33:59
0
3
569

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.

我想大声告诉你
我想大声告诉你

reply all(3)
小葫芦

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.

给我你的怀抱
Stage Area/Index Area(缓存区)

====================================

Working Area(工作区)

====================================

Untracking Area(未追踪文件,即新建文件)

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template