World map

 

BM: Baca dalam Bahasa Melayu

World 2: Undo Magic

Reset lab

You will learn: how git reset moves your branch back, in three modes.

The problem

Three commits in the repository. The newest one, Add day 2 entry, wobbles.

Your last commit was a mistake. It is only on your laptop. Can you step back one commit?

Watch

The main label and HEAD move back from Add day 2 entry to Add style. Add day 2 entry fades to a dashed dot.
6d3a9b1a8feb63270a76ebcf4670

reset: Move your branch back to an older commit. moves your branch back. HEAD~1 means “one commit before HEAD”. The mode decides where the undone changes go.

Try it

Try all three modes. Watch where the changes land.

Pick a reset type

6d3a9b1a8feb63270a76ebcf4670
Working folder
  • Empty
Staging area
  • Empty
Repository
  • 4 save points
  • Add day 2 entry
  • Add style
  • Add day 1 page

You tried 0 of 3.

Predict

You want to redo the commit. The changes should stay in the box. Which mode?

Pick one answer.

Watch

Before: index.html has an unsaved change, and Add day 2 entry is the newest commit. After: the commit and the change are both gone.

⚠️ Danger: --hard wipes the changes from your files too. Edits you never committed are lost for good. Use it only when you’re sure.

Try it

Undo the last commit. Keep the changes in your folder.

Working folder
  • Empty
Staging area
  • Empty
Repository
  • 4 save points
  • Add day 2 entry
  • Add style
  • Add day 1 page
6d3a9b1a8feb63270a76ebcf4670

Check

You type git reset HEAD~1 with no mode. Where do the changes go?

Pick one answer.

You did it!

You can now move your branch back, in three different ways.

Go deeper (optional)

HEAD~2 goes back two commits. You can also reset to a hash from git log --oneline. Reset rewrites history. Only reset commits that are still just on your computer. Shared commits need revert (next lesson).

After git reset --soft HEAD~1, index.html waits in the box and the log shows three commits. Terminal output: $ git reset --soft HEAD~1 $ git status -s M index.html $ git log --oneline 270a76e (HEAD -> main) Add style a8feb63 Add day 1 page 6d3a9b1 Add README