Track

Undoing Things

6 Lessons, then a Checkpoint of 3 Challenges.

Builds on Branching & Merging.

Lessons

Follow them in order, or play any Lesson once the Track is unlocked.

  1. Discarding and unstaging

    A file in a repository can have three versions at once:

    3 Challenges.

    New commands:

    • git restore
    • git restore --staged
  2. Fixing the last commit

    You've just committed, and then you spot a typo in the message. Or a file you forgot to add. You don't need a second commit to fix it: git commit --amend…

    3 Challenges.

    New commands:

    • git commit --amend
  3. Moving a branch back

    git reset <commit> moves the branch you're on to another commit. Usually that's back in time: git reset HEAD~1 moves it back one commit, and git reset HEAD~2…

    3 Challenges.

    New commands:

    • git reset
    • git reset --soft
    • git reset --mixed
    • git reset --hard
  4. Undoing in public

    Amend and reset rewrite history: they take commits off your branch. That's fine for commits only you have. But once you've shared a commit, by pushing it or…

    3 Challenges.

    New commands:

    • git revert
    • git revert --no-edit
    • git revert --abort
  5. Rescuing lost work

    Committed work is hard to lose. A reset, an amend or a deleted branch takes commits off a branch, but the commits themselves stay in the repository. What's…

    3 Challenges.

    New commands:

    • git reflog
  6. In the wild

    Until 2019, git had no switch and no restore. One command did both jobs: git checkout. It's still everywhere, in older tutorials, in answers online, in…

    3 Challenges.

    New commands:

    • git checkout
    • git checkout -b
    • git checkout --

Checkpoint

The Track ends with a Checkpoint of 3 Challenges that use only this Track's commands and those of the Tracks it builds on. Passing the Checkpoint completes the Track, even before you have played every Lesson.

Play the Undoing Things Checkpoint