Return to Video

Reset• GitHub & Git Foundations

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