So I told you that you should always review the stuff that you
have in the staging area before making a commit. So let's say we
review this changes. And we realize that the changes in file
one shouldn't go in the next commit, perhaps because these
changes are logically part of a different task. So we don't want
to have a commit that represents changes for different tasks,
right. So in this case, we want to undo the Add operation,
because earlier, we use the Add command to Add File one to the
staging area. Now we're going to undo this operation. How do we
do this? Well, in the past, we used the reset command. But a
lot of people found this command confusing, especially with
options such as hard or soft. That's why we have a new command
called restore. Now make sure you're using the latest version
of Git. Otherwise, what I'm going to show you is not going
to work on your machine. So here I'm using Git version 2.28. And
with this we can easily restore files in different environments,
in working directory or In the staging area, so git restore,
you're going to restore file one in the staging area. So we type
dash dash staged. And then we specify the file name, we can
list multiple files here, we can also use patterns. Or if you
want to restore everything in the staging area, we simply use
a period. So here I'm going to restore file one dot j s. Now,
when we run git status, again, you're not going to see a green
m here, because all the changes that we had in the staging area
are now in the working directory. Take a look. So git
status dash s. Look, we no longer have any changes for file
one in the staging area. All the changes are in the working
directory, it's essential for you to understand how the
Restore command works. The restore command essentially
takes the copy from the next environment. So in case of the
staging environment, what is the next environment, the last
commit? What do we have in the repository so When a restored
file one in the staging area, git took the last copy of this
file from the last snapshot and put it in the staging area. That
is what happened. Now look at file two file two is a new file,
because here we have a green A, which is short for added. So we
have this file, we have this new file in the staging area, but
this file doesn't exist in the last commit. So what do you
think will happen whenever you store this file? Well, because
we don't have a copy of this file in our repository or in our
last commit, Git is going to remove this file from the
staging area and take it back to its previous state, which is a
new untracked file. Let me show you. So git restore dash dash
staged file to the J s. Now, let's run git status again. So
file two is a new untracked file because we have two question
marks.