1 00:00:00,290 --> 00:00:03,060 Let's try running git log again. 2 00:00:03,060 --> 00:00:06,390 You've probably noticed a random looking strings of letters and 3 00:00:06,390 --> 00:00:09,480 numbers that accompany each commit in the log. 4 00:00:09,480 --> 00:00:12,110 Those strings are actually not random, 5 00:00:12,110 --> 00:00:16,780 the sting is the SHA1 checksum of all the changes in that commit. 6 00:00:16,780 --> 00:00:20,042 SHA stands for Simple Hashing Algorithm. 7 00:00:20,042 --> 00:00:23,930 The checksum is the result of combining all the changes in the commit and 8 00:00:23,930 --> 00:00:28,450 feeding them to an algorithm that generates these 40 character strings. 9 00:00:28,450 --> 00:00:31,390 There's no need to worry about the details of that algorithm. 10 00:00:31,390 --> 00:00:36,100 The part you should remember is that a checksum uniquely identifies a commit. 11 00:00:36,100 --> 00:00:38,110 Provide git that checksum later, and 12 00:00:38,110 --> 00:00:41,410 git will be able to find the commit that generated it. 13 00:00:41,410 --> 00:00:45,584 When you need to select a commit from your history, you can use these SHA1 14 00:00:45,584 --> 00:00:50,510 checksums or SHAs for short, to identify which commit you want. 15 00:00:50,510 --> 00:00:55,140 Git revert is just one of many commands that lets you specify a particular commit 16 00:00:55,140 --> 00:00:56,630 using a SHA. 17 00:00:56,630 --> 00:00:59,880 With git revert, the SHA is used to specify which commit 18 00:00:59,880 --> 00:01:02,590 contains the set of changes you want to undo. 19 00:01:02,590 --> 00:01:04,810 Let's try experimenting with this now. 20 00:01:04,810 --> 00:01:10,260 I'm going to run git log to show all the commits in our repo's history. 21 00:01:10,260 --> 00:01:12,620 I'll use the arrow keys to scroll down, 22 00:01:12,620 --> 00:01:15,600 back to the commit with the message of remove tin medals. 23 00:01:17,480 --> 00:01:20,300 I'll make note of the SHA from that commit. 24 00:01:20,300 --> 00:01:22,190 It let's us abbreviate commit SHA. 25 00:01:22,190 --> 00:01:23,520 So while I could copy and 26 00:01:23,520 --> 00:01:27,770 paste the whole thing, I can also type just the first five characters or so. 27 00:01:27,770 --> 00:01:30,080 So I'll remember C02BF, 28 00:01:30,080 --> 00:01:35,020 I'll press the Q key to exit out of the log and get back to the shell prompt. 29 00:01:35,020 --> 00:01:38,520 And now, I'll run the git revert command. 30 00:01:38,520 --> 00:01:40,338 To specify which commit to revert, 31 00:01:40,338 --> 00:01:43,680 I'll type in the partial SHA from the log as an argument c02bf. 32 00:01:43,680 --> 00:01:48,086 The revert command works by making a new commit, so 33 00:01:48,086 --> 00:01:53,560 it will open our editor, so we can edit the commit message. 34 00:01:53,560 --> 00:01:56,520 It has a default message of revert, 35 00:01:56,520 --> 00:01:59,750 followed by the commit message from the commit that you're reverting. 36 00:02:01,570 --> 00:02:05,390 In this case the result is Revert Remove tin metals. 37 00:02:05,390 --> 00:02:09,050 We'll just keep this default, I'll save the file with Ctrl+O, 38 00:02:09,050 --> 00:02:13,760 hit Enter to accept the existing file name, and hit Ctrl+X to exit the editor. 39 00:02:14,970 --> 00:02:16,980 Now let's run the git log command again. 40 00:02:18,030 --> 00:02:21,630 We'll see a new commit with the default message we saved in our editor, 41 00:02:21,630 --> 00:02:23,630 Revert Remove tin medals. 42 00:02:23,630 --> 00:02:26,130 And that commit will have a new SHA. 43 00:02:26,130 --> 00:02:30,006 Because the commit we selected deleted the tin.html file, 44 00:02:30,006 --> 00:02:34,780 the revert command makes a commit that adds the tin.html file. 45 00:02:34,780 --> 00:02:38,790 If we run ls, we'll see that tin.html file. 46 00:02:38,790 --> 00:02:42,940 And if we reopen the sidebar and refresh the file list, 47 00:02:44,720 --> 00:02:47,530 we'll see the tin.html file there. 48 00:02:47,530 --> 00:02:49,780 If we open the editor to look at its contents, 49 00:02:49,780 --> 00:02:52,530 it looks like those contents are back too. 50 00:02:52,530 --> 00:02:55,170 Let me just close the editor and hide the sidebar again. 51 00:02:56,560 --> 00:02:58,500 But after thinking about this some more, 52 00:02:58,500 --> 00:03:02,100 it's clear that bringing tin medals back is not a good idea. 53 00:03:02,100 --> 00:03:04,380 Let's run git log again, 54 00:03:04,380 --> 00:03:09,250 it shows us the commit that re-added the tin.html file right there at the top. 55 00:03:09,250 --> 00:03:11,180 It's the most recent commit. 56 00:03:11,180 --> 00:03:14,730 If we revert that commit, the file will be gone again. 57 00:03:14,730 --> 00:03:17,570 Now, normally, we'd need to make note of the commit SHA so 58 00:03:17,570 --> 00:03:20,040 we can provide it to the git revert command. 59 00:03:20,040 --> 00:03:22,200 But because this is the most recent commit, 60 00:03:22,200 --> 00:03:24,720 there's a special shorthand we can use. 61 00:03:24,720 --> 00:03:30,720 I'll press Q to quit out of the log, and I'll type git revert HEAD. 62 00:03:32,640 --> 00:03:37,980 HEAD in all capital letters is a shorthand meaning the most recent commit. 63 00:03:37,980 --> 00:03:42,210 We could use the full SHA for the most recent commit here or an abbreviated SHA. 64 00:03:42,210 --> 00:03:44,550 But if we type all caps HEAD, 65 00:03:44,550 --> 00:03:48,880 git will operate on whichever commit is the most recent one at that time. 66 00:03:48,880 --> 00:03:52,350 You can use the head short hand in place of a commit SHA in 67 00:03:52,350 --> 00:03:54,910 any git command that accepts SHA. 68 00:03:54,910 --> 00:03:57,650 I'll press Enter to run the command and as before, 69 00:03:57,650 --> 00:04:01,560 git revert will start a new commit that reverts the commit we selected. 70 00:04:01,560 --> 00:04:06,400 The default message is now revert remove tin medals. 71 00:04:06,400 --> 00:04:10,220 While that's a complex description of what the commit does, it's also true. 72 00:04:10,220 --> 00:04:14,190 And since we're just experimenting, I won't bother editing this one either. 73 00:04:14,190 --> 00:04:16,530 I'll press Ctrl+O to write out the file. 74 00:04:16,530 --> 00:04:21,290 Press Enter to accept the existing file name and press Ctrl+X to exit the editor. 75 00:04:21,290 --> 00:04:23,990 And git will complete the revert commit. 76 00:04:23,990 --> 00:04:26,420 Now if I run git log, 77 00:04:26,420 --> 00:04:30,600 we'll see another new commit at the top with the default commit message we saved. 78 00:04:30,600 --> 00:04:32,780 And if I quit the log and 79 00:04:32,780 --> 00:04:38,430 run ls to get a list of files again, we'll see the tin.html file is gone. 80 00:04:38,430 --> 00:04:41,630 We can also run git status again, and 81 00:04:41,630 --> 00:04:44,710 it will show that the removal of the file has already been committed. 82 00:04:45,970 --> 00:04:47,410 In this second stage, 83 00:04:47,410 --> 00:04:51,230 we've shown you how to maintain files you've committed to a git repo. 84 00:04:51,230 --> 00:04:54,670 Practicing your new skills is important to making them stick, so 85 00:04:54,670 --> 00:04:59,190 be sure to check the teacher's notes on this video for some practice ideas. 86 00:04:59,190 --> 00:05:01,830 In the third and final stage of this course, 87 00:05:01,830 --> 00:05:05,320 we'll show you how to share you work by cloning a repo, see you there.