Lesson 29 +25 XP

Project 3: Fix a Mistake

Project 3: Fix a Mistake

Learn to undo mistakes safely with revert, reset, and amend.

Setup

Use a small repo with at least two commits, each adding a line to a file.

Task 1: Amend a message

You typed a bad commit message. Fix the last one:

git commit --amend -m "Much better message"

Task 2: Revert a commit

Add a commit that you decide is a bad idea, then undo it without rewriting history:

git revert HEAD

A new "Revert" commit appears on top, and the bad change is gone from the file.

Task 3: Undo a commit but keep the work

git reset --soft HEAD~1

Your last commit disappears from history, but the changes stay staged.

Task 4: Recover with reflog

Do a git reset --hard HEAD~1, then recover the lost commit:

git reflog
git reset --hard <hash from reflog>

Your work is back.

TL;DR

  • git commit --amend fixes the last commit.
  • git revert undoes a commit safely.
  • git reset --soft undoes a commit but keeps changes.
  • git reflog rescues lost commits.