Git reset is the command that allows you to shape history in your repository. Whether you're undoing some changes or crafting your commits differently, this is the command for you. ♪ (bossa music) ♪ Welcome to the episode of Git and GitHub Foundations on the reset command. This command has a lot of power, and a lot of modes. Yeah, there's going to be three modes we're going to be working with here. There's going to be soft; mixed, or the default; and hard. ♪ (music) ♪ These adjectives are pretty descriptive, starting with the one that's the default, mixed. It alters both the history as well as the working directory. So mixed, both things. And soft is going to take one or multiple commits and put all of their changes back into the staging area to allow you to continue to craft a new commit out of that. Hard, on the other hand, is a destructive operation that's meant to erase things that you no longer wish to keep. So with all three of these in our stable, let's look at mixed first. Mixed is the recommendation that gets most often shown to new Git users because it shows up in the status command. When you have changes in the staging area and you say git status, we see git reset HEAD. That allows us to take those changes out of the staging area and put them back into the working directory with the mixed option. Soft is the way that I take some changes that might have gotten too granular in nature. One, two, three, four, five commits that I then realize all belong in one transaction, and to bring them all together by a git reset --soft HEAD~5 the most recent five commits. So with that command of using soft you can take all five of those commits and kind of squash them down into the staging area as one commit. Pretty useful for reshaping history, but reshaping history goes to the far end of the spectrum to throw away commits that just don't add value. You don't want to send them, transmit them, or share them with others. That's where hard comes into play. If you completely want to throw away some of your work, maybe you're trying out some change that just didn't work out, you can use the git reset --hard to throw those commits away completely. People might ask, then why would you make a commit? But Git provides you a really nice safety net through the reflog command that we'll look at in a future episode that motivates you to make checkpoints with commits, and knowing that you have hard at your disposal, you can clean that history up anytime you like. ♪ (music) ♪ There is one other cousin command that is often talked about with reset and that's the checkout command. The checkout command is of a different granularity than reset, which typically operates on the entire history of a repository. Checkout is focused more on a directory or a file level precision. Instead of undoing or changing an entire commit, we can go back in history to a specific file at a commit and pull that file and its version back to our current working directory. Clear communication is the goal of all Git repository history. So whether it's git reset hard, reset soft, reset mixed, or the more precise checkout command, use these to provide clear intent about your changes to your colleagues. Git reset is a tool that can be a little bit intimidating to new users of Git. But it can be a powerful tool to have at your disposal for crafting beautiful repository history. Thanks for watching another episode of Git and GitHub Foundations on reset. As always, don't forget to subscribe to any of our channels on the side here. Questions or comments, put those down below or check out one of our other educational topics on Git and GitHub here at the bottom. ♪ (music) ♪ (voices silenced)