1 00:00:00,860 --> 00:00:05,120 In the previous video, we staged a change to medals.html that added 2 00:00:05,120 --> 00:00:09,030 a heading announcing a 100% off sale. 3 00:00:09,030 --> 00:00:13,060 We decided that it was a bad idea, so we unstaged the change. 4 00:00:13,060 --> 00:00:17,971 But the medals.html file saved in our working directory still has that 100% off 5 00:00:17,971 --> 00:00:19,090 heading. 6 00:00:19,090 --> 00:00:22,260 Now, this change is small enough that it would be easy to go in and 7 00:00:22,260 --> 00:00:23,598 remove manually. 8 00:00:23,598 --> 00:00:28,360 But in a more complex project, the change could affect dozens of lines. 9 00:00:28,360 --> 00:00:33,210 That's why git offers a command to discard changes to a file automatically. 10 00:00:33,210 --> 00:00:33,930 By the way, 11 00:00:33,930 --> 00:00:39,190 remember how in an earlier video I said git can undo almost any mistake you make? 12 00:00:39,190 --> 00:00:42,770 We're about to show you something git can't undo. 13 00:00:42,770 --> 00:00:46,860 The changes in the medals.html have never been committed, so 14 00:00:46,860 --> 00:00:49,180 git doesn't have them stored anywhere. 15 00:00:49,180 --> 00:00:51,860 And we're about to erase those changes. 16 00:00:51,860 --> 00:00:54,840 When you're discarding changes to a modified file, make 17 00:00:54,840 --> 00:00:58,960 absolutely sure that you're not discarding changes you actually wanted to keep. 18 00:01:00,200 --> 00:01:05,440 Okay, with that warning out of the way, let's get rid of this 100% off heading. 19 00:01:05,440 --> 00:01:11,340 Let's run the git status command, and we'll see another helpful hint here. 20 00:01:11,340 --> 00:01:16,620 Use git checkout with the file name to discard changes in the working directory. 21 00:01:16,620 --> 00:01:20,440 The git checkout command has a couple different uses. 22 00:01:20,440 --> 00:01:25,260 If you don't specify any file names, git checkout switches between branches. 23 00:01:25,260 --> 00:01:27,920 We won't be talking about branches in this course, so 24 00:01:27,920 --> 00:01:30,290 we won't be covering that usage here. 25 00:01:30,290 --> 00:01:35,140 If you do specify file names, the contents of those files will be overwritten 26 00:01:35,140 --> 00:01:36,920 with their last committed versions. 27 00:01:37,960 --> 00:01:41,610 Let's try this command out on the medals.html file. 28 00:01:41,610 --> 00:01:43,720 We type the git checkout command. 29 00:01:43,720 --> 00:01:48,080 Then we use some special syntax that is mainly used together with git checkout, 30 00:01:48,080 --> 00:01:51,920 a space, a pair of dashes, and another space. 31 00:01:51,920 --> 00:01:54,370 This is not a command line option. 32 00:01:54,370 --> 00:01:58,370 An option would be followed by an option name rather than a space. 33 00:01:58,370 --> 00:02:01,760 Instead, it's a separator that makes it clear to Git 34 00:02:01,760 --> 00:02:05,460 that any arguments that follow will be file names. 35 00:02:05,460 --> 00:02:09,710 Finally, we type the name of one or more files we want to discard changes for. 36 00:02:09,710 --> 00:02:13,520 In this case, it will be just medals.html. 37 00:02:13,520 --> 00:02:15,470 Hit Return to run the command. 38 00:02:15,470 --> 00:02:20,150 There won't be any output, which as usual, just means that it was successful. 39 00:02:20,150 --> 00:02:22,410 Now we can run git diff again. 40 00:02:22,410 --> 00:02:26,450 Since the changes have been discarded, it no longer shows any output. 41 00:02:26,450 --> 00:02:29,950 We can also run get status again, and 42 00:02:29,950 --> 00:02:32,430 we'll see that the working directory is clean. 43 00:02:32,430 --> 00:02:35,397 There are no files that have been modified since the last commit, 44 00:02:35,397 --> 00:02:36,177 or rather, 45 00:02:36,177 --> 00:02:41,700 our medals.html file has been changed back its state as of the last commit. 46 00:02:41,700 --> 00:02:44,000 By undoing the modifications to this file, 47 00:02:44,000 --> 00:02:46,920 we have made another backwards transition here. 48 00:02:46,920 --> 00:02:50,100 We've taken a modified file in our working directory and 49 00:02:50,100 --> 00:02:54,150 updated its contents to look like they did in the previous commit. 50 00:02:54,150 --> 00:02:58,640 We rewound the file from its modified state back to its last committed state.