< Return to Video

Reset• GitHub & Git Foundations

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

more » « less
Video Language:
English
Team:
GitHub
Project:
Git and GitHub Foundations
Duration:
03:48
There has been no activity on this language so far.

English subtitles

Revisions Compare revisions