So now you know that once Git tracks a file, it stores every
version of that file in its database. And that means if you
screw things, we can always restore a file or a directory to
a previous version. So in this demo, I'm going to delete a file
and then show you how to restore it. It's very easy. So we're
going to delete file one dot J s, I told you that if we use the
rm command in Linux, or Unix based systems, this will only
remove the file from the working directory. So then we'll have to
state the change or the deletion. A better way is to use
the Git rm command. This will remove the file from both the
working directory as well as the staging area. Okay. Now let's
get a short status. So in the staging area, we have a deleted
file. Now, let's make a commit, delete file one dot J s.
Alright, now let's say shoot, we shouldn't have deleted this
file. So what can we do here? Well, we have a few options. We
can undo or revert the last commit. We're going to talk
about that later in the course. But in this lesson, I want to
talk about restoring a file to a previous version, not undoing a
commit. So let's look at our history. Alright, so here's our
history, we want to restore file one to the commit before the
last commit, that is coming over here. So we type Git restore.
Now let's have a quick look at the documentation. The restore
command takes three types of arguments, we can supply a bunch
of options, we can supply a source, you haven't done this so
far. So by default, git will restore that file from the next
environment or the next area. So if the file we want to restore
is in the working directory gets we'll restore it from the
staging area. And if the file is in the staging area, it will
restore it from the last snapshot or the last commit. Now
in this case, we want to change the default behavior. We want to
restore a file from the commit before the last one. So we type
git restore data source, we set it to head tilda one. And then
we specify the full path to the file. In this case, file one dot
j s. Now, let's get a short status. So we have a new
untracked file. So this is how we can restore a file to a
previous version.