>_ IzzyLab

Hands-on task

This task is step 9 of the course “Everyday Git”

Revert the bad commit

easy~3 min

The last commit in /root/project broke the application. Revert it in a way that preserves history (don't rewrite it with a force push): create a new commit that undoes the changes of the last one. The file broken.txt added by that commit must then disappear from the working tree.

What you'll practise:
  • git
  • git revert
  • reverting a commit
  • git history
  • HEAD

Topic breakdown

You can undo a commit in two fundamentally different ways. git reset moves the branch pointer back and erases the commit from history — this is rewriting history, which is unacceptable for already-published commits, because colleagues' trees will diverge. The safe alternative is to create a new commit on top that computes and applies the inverse patch of the unwanted one: history then only grows forward and nothing is lost. The task is about when you must not rewrite history and how to undo changes without touching existing commits.

What's checked

  1. broken.txt removed from the working tree
  2. history preserved, a revert commit was added
  3. the app.txt file is preserved
  4. on top is a commit undoing the breaking one

What it looks like