Last answered:

14 Nov 2023

Posted on:

21 May 2021

0

git checkout vs git reset

It's not clear what the difference between the two? When should we use one command or the other? Thanks in advance

2 answers ( 0 marked as helpful)
Posted on:

16 Nov 2022

0

use soft command when you want to move HEAD to previous commit and at the same time the changes would be staged.
Use mixed command when you want to move HEAD to some previous commit and at the same time the changes would be unstaged.
And use hard command when you want to move HEAD to some previous commit and also to go back to previous version of the file.

Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

14 Nov 2023

0

git checkout is like time check point. Imagine you are a time traveler, you can go back in time either just to observe or alter the course of history, making a new branch.
let say you have commits A->B->C->D (HEAD/current version)
then you checkout to B.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.


If you made some changes and committed it and you want to keep it,

you can just create a new branch and name it with git switch -c <branch-name>. *let's call it testing-branch

So you will have your main branch (master) and one additional branch (testing-branch).

You will have something like
A->B->C->D | (master branch)

      \

       E            | (testing-branch)


While git reset will do what Sanchit explained above.

CMIIW

Submit an answer