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