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