World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Which undo?

You will learn: how to pick restore, reset or revert for each mistake.

The problem

Mistakes everywhere: a changed file in the working folder, a file in the box and a bad commit in the repository. They all wobble.

restore, reset, revert. Three undo words that sound alike. Pick the wrong one, and you might lose work.

Watch

The changed tag on index.html disappears. The file is back to its saved version.

Mistake not committed yet? Use restore: Put a file back to a saved version.. It fixes files in your folder or in the box.

Watch

The main label and HEAD move back one commit. The newest commit fades to a dashed dot.
6d3a9b1a8feb63270a76ebcf4670

Commit only on your laptop? Use reset: Move your branch back to an older commit.. It moves your branch back, as if the commit never happened.

Watch

A new undo commit appears at the end. Every older commit stays.
6d3a9b1a8feb63270a76eac9bec3839ee20

Commit already shared? Use revert: Make a new commit that undoes an old one.. It adds a new commit that undoes the bad one.

Try it

Sort each mistake into the right undo.

Drag a card into a box. Or tap the card, then tap the box.

        Check

        Which one can lose work for good?

        Pick one answer.

        You did it!

        You can now pick the right undo for any mistake.

        Go deeper (optional)

        A quick map. Pick by where the mistake lives.

        Not committed      → git restore <file>
        In the box         → git restore --staged <file>
        Last commit, typo  → git commit --amend
        Only on my laptop  → git reset HEAD~1
        Already shared     → git revert <commit>