Hello, dear students, in this lesson, we are going to learn in detail what is Guter said command
and how we can use it.
We'll start from the problem statement and when we might want to use it afterwards.
We'll learn in theory how it works to understand how users networks will.
Compared with Check-Out Command, we'll use three different modes how to reset my work served mixed
and hard.
Besides a series overview.
One real example.
I'm going to show you how you might use this command in your repository.
Let's start.
So why do you need to use get reset command, get reset.
Command is a really powerful tool that will help you to undo changes.
It might happen that you created snapshots that you don't need anymore, or probably for some reasons
you want to remove commands from your local branch, but you don't want to remove changes from your
working directory for such cases.
Get reset.
Command might be used.
You can find tutorials on the Internet.
But in my opinion, they're really hard to understand for the people who have never had experience with
it.
That's why in this lesson, I will try to explain this topic from the practical point of view to help
you understand the topic better to understand how to reset command work.
Let's compare it with Check-Out Command.
Here's our Master Branch and here's our head pointer that points to the latest snapshot on this branch.
So what happened when we call you checkout command, when we try to switch to another commit?
We can execute Gitche called command with the region, checksum where we want to switch our head pointer
in this particular scenario, if checksum is me, then I can move head pointer by executing command
Check-Out B But the master branch is still pointing out to the latest command here.
If you remember, during one of our lessons we discussed Detached Heads State.
This is exactly the scenario of detached head.
So what does research come and do that is different from Chicot?
Come on.
In the case I will use gets reset command.
We check some of the specific revision that will move both head pointer and current branch pointer to
the specific revision.
That's what it always does.
No matter what option will be used with reset command.
Can you see the difference on this visualization?
Hope it is clear now what reset command does.
But besides updating of command pointers like head pointer and branch pointer, reset command will also
update the state of our staging area and update the state of our country.
That is our files in our file system.
Updates in the staging area and our country will be different depending on what mode of reset we are
going to use as a result from agenda.
There are three possible modes soft, mixed and hard.
Let's learn right now what will happen in case we reset in soft mode.
If we use get reset with soft option, we still move ahead and branch pointers to the specific region
and that's it.
Nice and above that changes from your working tree will be there and in the staging area.
In simple words, the changes that you did in files before reset and commit these changes, you will
be present in files of your project.
Moreover, these changes will be in the staging area in case after asset in soft mode.
You would call your status command.
You would find all your changes added to the staging area in green color.
Execution of command is going to lead you directly to the state where you were before 7:00.
Here on this slide, you can see that soft mode keeps all changes in the staging area.
In case you are going to use mixed option, it is similar to softwoods.
Only one difference changes still will be present in the working directory, but they won't be present
in the staging area.
In simple words, you still will be able to find the changes in files, but when you will call git status,
you're going to see that all changes are not added to the staging area.
You would need to perform it add and after that you commit command in case you want to restore the state
before setting the previous two options you might want to use when you kind of okay with changes that
you have done.
But you have to do some modifications in the good history.
The first option for that is really hard.
This is the most direct and dangerous option that is frequently used after executing this reset.
Command was a hard option.
Get will make sure that your staging area and are working very much that of the specific commit in simple
words, your file system will be the same as it was after which you specified in reset command when
this mode is needed.
Personally, I used this command a lot when I realized that I messed up completely the state of my files
and I want to get everything back as it was when it worked, at least somehow.
Sometimes you might want to reset the state of some specific revision.
Probably you want to reset state of your local repository to the state that you have in the remote repository.
You might want to do so in case something went wrong.
During The Amazing today you're in the demo.
I will show you how to reset your changes in different modes.
Now, when you understood the theory, let's practice a bit and I'll show you how you can use gets reset
command in different modes.
We are on the Master Branch.
Let's check our gate history gate log dash three.
Here is a command that we did during this course.
You remember we added stock management service and created separate snapshots for that.
Afterwards we credit card management service file and created separate snapshots for that.
And after that I did create HTML file homeport HTML for our lessons to understand much conflict topic.
Remember that.
Let me show you, for example, that after soft reset to the state of the Stock Management Command Card
Management Service and home e-mail are still present in the country, but the state of the branch and
head pointer is different.
Guter said was option soft e 71, A five, b, I entered first characters of this commit and press enter.
Let's check our comment history to understand where we are now.
Get lost there.
Three You see here in parenthesis that our head and master pointers are on this comment.
Let me check its status and its status and you can see the two files from the documents are present
in my file system and automatically added to the staging area to return my project to the state where
it was before the reset.
But with a new command, I have to come them one more time, get command with option and court management
and home HMO.
And we created new command with these changes.
Now I want to demo to you makes the more me find commands that we recently used and just change it a
bit.
Here it is.
Let me removed soft here, by the way.
Mixed mode is a default.
That means you shouldn't necessarily write me here.
You can just remove any options here.
That would mean resetting in the default mixed mode.
Let me check it lock now it log Destry.
I'm on the committee where I wanted to be and like check status now get status.
And you can see that files are present in my work entry in my file system, but they are not in the
staging area.
Can you understand the difference between soft and mixed mode now?
The return the previous state I should execute get at DOD command and after that it changes.
Let's use the same messages previously for the sake of the demo.
Awesome, and let me show you the last but not the least option, hard lessons said enhancement to this
commit spaces are added to the hello world.
While we should see how the state of our file system will be different from that e-mail, card management
servers and stock management service files would disappear.
Let's reset resorption heart two six seven two six F..
Let's check in with history now.
Get logged three.
OK, our head pointer and branch are pointing to the committee that we expect, but what is with our
filesystem now?
It's status and we can see that there is nothing to commit, and that is my voluntary claim, I'm in
the Israeli folder right now.
Let me check the state of the file system unless there shall we can see that I have only discount completion
service and hello, world file.
I do not have Nasacort nor stock folders where my other files were stored.
Now you can see how it was that was hard option, Kenora said.
The state of the file system.
One more trick, probably in some lessons.
You saw that I researched state of the branch without reference to the specific checks, but using relative
navigation from the head pointer.
Let me show you one more time.
Get reset with option heart had to the three.
You can see how I can move that Anabranch pointer to three cm is back from the point where I was.
This is pretty convenient.
As for me, probably you would also use this variation of reset command.
And one more real life scenario, imagine that you wanted either to squash commits or a message or something
else went wrong during the invasion or during the development.
And you want to reset the state of your working tree, your file system, as it is in a remote repository
right now.
What I recommend you to do, the first thing that I always do is execution of each command with option
like this need fetch resorption.
All this is just to make sure that you fetch the latest state of the remote repository after that reset
with the hard option to the State of Origin branch.
In this particular case, we played with our master branch and I want to restore the state of our region.
Must have branch reset with option, heart or region slash master.
And you can see that I'm on the latest commit right now.
So there you saw that in reset command.
You can use chametz checksum, relative amount of comments from the head pointer and even specific branch,
I believe.
Now you know about reset command even more than some senior software engineers.
Hope you enjoyed the lesson.
Let's recap what we have learned today.
Today, we learned what is a good reset command and when we can use it.
We understand the difference between reaching out and gives reset command.
You learn three modes of reset command, soft, mixed and hard on the real example.
You saw how to reset state of the branch if you coming back from the head pointer or to the specific
command.
Also, you learned how to reset state of the branch to the state of the branch in the remote repository.
That's all what I planned to talk about in this lesson with you.
Thanks a lot for your attention and see you in the next lesson.