World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Undo safely with revert

You will learn: how to undo a shared commit without rewriting history.

The problem

Three commits: Add style, Make heading blink and Add day 2 entry. Make heading blink wobbles.

Two commits ago, you made the heading blink. Everyone hates it. Your team already has that commit.

Watch

A new commit, Revert Make heading blink, appears at the end. All the older commits stay where they were.
6d3a9b1a8feb63270a76eac9bec3839ee20

revert: Make a new commit that undoes an old one. adds a new commit that does the opposite. The bad commit stays in history. Nothing is erased.

Try it

Tap the commit that made the heading blink.

Tap the bad commit.

6d3a9b1a8feb63270a76eac9bec3839ee20

Predict

You revert “Make heading blink”. Is your day 2 entry still there?

Pick one answer.

Try it

Now revert the blink commit in the terminal.

6d3a9b1a8feb63270a76eac9bec3839ee20

Check

Your bad commit is already on GitHub. Which undo do you pick?

Pick one answer.

You did it!

You can now undo a shared commit without breaking anyone’s history.

Go deeper (optional)

In real Git, git revert opens your editor with a ready message. Save and close it. --no-edit skips the editor. Did later commits change the same lines? Then you get a conflict. Conflicts come in World 3.

git revert --no-edit HEAD~1 makes the undo commit without opening an editor. Terminal output: $ git revert --no-edit HEAD~1 [main bd92bf2] Revert "Make heading blink" 1 file changed, 1 deletion(-) $ git log --oneline bd92bf2 (HEAD -> main) Revert "Make heading blink" 839ee20 Add day 2 entry ac9bec3 Make heading blink 270a76e Add style a8feb63 Add day 1 page 6d3a9b1 Add README