1 00:00:03,990 --> 00:00:06,540 So I told you that you should always review the stuff that you 2 00:00:06,540 --> 00:00:10,290 have in the staging area before making a commit. So let's say we 3 00:00:10,290 --> 00:00:13,620 review this changes. And we realize that the changes in file 4 00:00:13,620 --> 00:00:16,770 one shouldn't go in the next commit, perhaps because these 5 00:00:16,770 --> 00:00:20,370 changes are logically part of a different task. So we don't want 6 00:00:20,370 --> 00:00:23,370 to have a commit that represents changes for different tasks, 7 00:00:23,430 --> 00:00:26,820 right. So in this case, we want to undo the Add operation, 8 00:00:26,970 --> 00:00:30,330 because earlier, we use the Add command to Add File one to the 9 00:00:30,330 --> 00:00:33,840 staging area. Now we're going to undo this operation. How do we 10 00:00:33,840 --> 00:00:38,310 do this? Well, in the past, we used the reset command. But a 11 00:00:38,310 --> 00:00:40,920 lot of people found this command confusing, especially with 12 00:00:40,950 --> 00:00:44,820 options such as hard or soft. That's why we have a new command 13 00:00:44,820 --> 00:00:48,180 called restore. Now make sure you're using the latest version 14 00:00:48,180 --> 00:00:50,520 of Git. Otherwise, what I'm going to show you is not going 15 00:00:50,520 --> 00:00:55,800 to work on your machine. So here I'm using Git version 2.28. And 16 00:00:55,800 --> 00:00:58,740 with this we can easily restore files in different environments, 17 00:00:58,890 --> 00:01:03,540 in working directory or In the staging area, so git restore, 18 00:01:04,230 --> 00:01:08,970 you're going to restore file one in the staging area. So we type 19 00:01:09,270 --> 00:01:13,920 dash dash staged. And then we specify the file name, we can 20 00:01:13,920 --> 00:01:17,970 list multiple files here, we can also use patterns. Or if you 21 00:01:17,970 --> 00:01:20,850 want to restore everything in the staging area, we simply use 22 00:01:21,000 --> 00:01:26,550 a period. So here I'm going to restore file one dot j s. Now, 23 00:01:26,940 --> 00:01:29,970 when we run git status, again, you're not going to see a green 24 00:01:29,970 --> 00:01:32,790 m here, because all the changes that we had in the staging area 25 00:01:32,970 --> 00:01:36,420 are now in the working directory. Take a look. So git 26 00:01:36,420 --> 00:01:41,040 status dash s. Look, we no longer have any changes for file 27 00:01:41,040 --> 00:01:44,400 one in the staging area. All the changes are in the working 28 00:01:44,400 --> 00:01:47,760 directory, it's essential for you to understand how the 29 00:01:47,760 --> 00:01:50,640 Restore command works. The restore command essentially 30 00:01:50,640 --> 00:01:54,390 takes the copy from the next environment. So in case of the 31 00:01:54,390 --> 00:01:57,420 staging environment, what is the next environment, the last 32 00:01:57,420 --> 00:02:00,840 commit? What do we have in the repository so When a restored 33 00:02:00,840 --> 00:02:04,020 file one in the staging area, git took the last copy of this 34 00:02:04,020 --> 00:02:07,260 file from the last snapshot and put it in the staging area. That 35 00:02:07,260 --> 00:02:11,100 is what happened. Now look at file two file two is a new file, 36 00:02:11,460 --> 00:02:14,370 because here we have a green A, which is short for added. So we 37 00:02:14,370 --> 00:02:17,310 have this file, we have this new file in the staging area, but 38 00:02:17,310 --> 00:02:20,970 this file doesn't exist in the last commit. So what do you 39 00:02:20,970 --> 00:02:24,330 think will happen whenever you store this file? Well, because 40 00:02:24,330 --> 00:02:27,210 we don't have a copy of this file in our repository or in our 41 00:02:27,210 --> 00:02:29,730 last commit, Git is going to remove this file from the 42 00:02:29,730 --> 00:02:32,970 staging area and take it back to its previous state, which is a 43 00:02:32,970 --> 00:02:38,580 new untracked file. Let me show you. So git restore dash dash 44 00:02:38,610 --> 00:02:44,880 staged file to the J s. Now, let's run git status again. So 45 00:02:44,880 --> 00:02:47,970 file two is a new untracked file because we have two question 46 00:02:47,970 --> 00:02:48,420 marks.