1 99:59:59,999 --> 99:59:59,999 git reset is the command that allows you to shape history in your repository. 2 99:59:59,999 --> 99:59:59,999 Whether you're undoing some changes or crafting your commits differently, 3 99:59:59,999 --> 99:59:59,999 this is the command for you. 4 99:59:59,999 --> 99:59:59,999 (bossa music) 5 99:59:59,999 --> 99:59:59,999 Welcome to the episode of Git and GitHub Foundations on the reset command. 6 99:59:59,999 --> 99:59:59,999 This command has a lot of power, and a lot of modes. 7 99:59:59,999 --> 99:59:59,999 Yeah, there's going to be three modes we're going to be working with here. 8 99:59:59,999 --> 99:59:59,999 There's going to be soft; mixed, or the default; and hard. 9 99:59:59,999 --> 99:59:59,999 (music) 10 99:59:59,999 --> 99:59:59,999 these adjectives are pretty descriptive, 11 99:59:59,999 --> 99:59:59,999 starting with the one that's the default, mixed. 12 99:59:59,999 --> 99:59:59,999 It alters both the history and the working directory. 13 99:59:59,999 --> 99:59:59,999 So mixed, both things. 14 99:59:59,999 --> 99:59:59,999 And soft is going to take one or multiple commits 15 99:59:59,999 --> 99:59:59,999 and put all of their changes back into the staging area 16 99:59:59,999 --> 99:59:59,999 to allow you to continue to craft a new commit out of that. 17 99:59:59,999 --> 99:59:59,999 Hard, on the other hand, is a destructive operation 18 99:59:59,999 --> 99:59:59,999 that's meant to erase things that you no longer wish to keep. 19 99:59:59,999 --> 99:59:59,999 So with all three of these in our stable, 20 99:59:59,999 --> 99:59:59,999 let's look at mixed first. 21 99:59:59,999 --> 99:59:59,999 Mixed is the recommendation that most often gets shown to new Git users 22 99:59:59,999 --> 99:59:59,999 because it shows up in the status command. 23 99:59:59,999 --> 99:59:59,999 When you have changes in the staging area and you say git status, 24 99:59:59,999 --> 99:59:59,999 we see a Git reset head. 25 99:59:59,999 --> 99:59:59,999 That allows us to take those changes out of the staging area 26 99:59:59,999 --> 99:59:59,999 and put them back into the working directory 27 99:59:59,999 --> 99:59:59,999 with the mixed option. 28 99:59:59,999 --> 99:59:59,999 Soft is the way that I take some changes 29 99:59:59,999 --> 99:59:59,999 that might have gotten too granular in nature. 30 99:59:59,999 --> 99:59:59,999 One, two, three, four, five commits 31 99:59:59,999 --> 99:59:59,999 that I then realize all belong in one transaction, 32 99:59:59,999 --> 99:59:59,999 and to bring them all together by a git reset --soft HEAD~5 33 99:59:59,999 --> 99:59:59,999 the most recent five commits. 34 99:59:59,999 --> 99:59:59,999 So with that command of using soft 35 99:59:59,999 --> 99:59:59,999 you can take all five of those commits 36 99:59:59,999 --> 99:59:59,999 and kind of squash them down into the staging area as one commit. 37 99:59:59,999 --> 99:59:59,999 Pretty useful for reshaping history, 38 99:59:59,999 --> 99:59:59,999 but reshaping history goes to the far end of the spectrum 39 99:59:59,999 --> 99:59:59,999 to throw away commits that just don't add value. 40 99:59:59,999 --> 99:59:59,999 You don't want to send them, transmit them, or share them with others. 41 99:59:59,999 --> 99:59:59,999 That's where hard comes into play. 42 99:59:59,999 --> 99:59:59,999 If you completely want to throw away some of your work, 43 99:59:59,999 --> 99:59:59,999 maybe you're trying out some change that just didn't work out, 44 99:59:59,999 --> 99:59:59,999 you can use the git reset --hard to throw those commits away completely. 45 99:59:59,999 --> 99:59:59,999 People might ask, then why would you make a commit? 46 99:59:59,999 --> 99:59:59,999 But Git provides you a really nice safety net 47 99:59:59,999 --> 99:59:59,999 through the reflog command that we'll look at in a future episode 48 99:59:59,999 --> 99:59:59,999 that motivates you to make checkpoints with commits, 49 99:59:59,999 --> 99:59:59,999 and knowing that you have hard at your disposal, 50 99:59:59,999 --> 99:59:59,999 you can clean that history up anytime you like. 51 99:59:59,999 --> 99:59:59,999 (music)