The difference between git reset and git checkout

1. git reset

As we all know, git reset --hard 'version hash' can be used to roll back the version, but without the --hard parameter, git reset can be used to restore from the temporary storage to the workspace.

Simple scenario use case: Suppose two files are modified at a time, but these two files need to be submitted twice. When performing a cache operation (git add), both files are accidentally cached. At this time, we Need to cancel the cache of one of the files, at this time you need to git resetoperate to achieve, as shown below:
Insert picture description here

Two. Git checkout

git checkout is generally used to switch branches. In fact, there is 通过git commit之后another way to modify the files in it, and restore the files that were not put into the cache area (git add) to the working area.

For which files have been modified, we can also use the git diff command to see what has been modified.

as follows:
Insert picture description here

Published 398 original articles · Liked 182 · Visits 370,000+

Guess you like

Origin blog.csdn.net/yexudengzhidao/article/details/105243564