0/3

Lesson05

intermediate

Safe Undo with git revert

Goal

Undo a commit that others already have, without rewriting history.

Yesterday's Add dark mode commit broke the site, and it is already on the shared main branch: your teammates have pulled it. Resetting would rewrite history under their feet.

Undo the dark mode with a new commit instead, keeping everything after it.

Objectives

0/3
  1. main has a commit reverting Add dark mode. (Current objective)
  2. The original Add dark mode commit is still in the history. (Not started)
  3. Fix footer, which came after it, is still there too. (Not started)

Your task nowStep 1 of 3

main has a commit reverting Add dark mode.

Need help?

Reference

Reverting a commit

$ git revert HEAD~1

[main 4c2a9e1] Revert "Add dark mode"
 1 file changed, 1 deletion(-)

Git works out the opposite of that commit's changes and records them as a new commit. The original stays in the history, so anyone can see what happened and why.

History only grows

Step 1 of 2

The bad commit B is followed by C, which is fine.

Step 1 of 2. The bad commit B is followed by C, which is fine.

Preparing your workspace…

Repository Graph

Click a commit to inspect it

0 commits

Working Tree

Not a Git repository yet

No unstaged changes

Your working tree matches the staging area.

Staging Area

Files prepared for the next commit

No staged changes

Use git add to prepare files for your next commit.

Repository

Committed history

No commits yet

Use git commit to record staged changes.