Skip to content
Lab 2 of 3

History Surgery: Undo, Recover & Cherry-pick

Things go wrong in git — and almost nothing is truly lost. Safely revert a bad commit on shared history, rescue a commit you 'deleted' with the reflog, and cherry-pick a single fix off another branch.
  • Intermediate
  • 45 min
  • Git
  • Recovery
  • reflog
  • Version control

Overview

The fastest way to stop fearing git is to learn that it almost never throws anything away. In this lab you'll operate on ~/repo, a project with a few mistakes baked in.

You'll revert a bad commit the safe way — a new commit that undoes it, never rewriting shared history — recover a commit that a hard reset wiped out using the reflog (git's private undo journal), and cherry-pick exactly one useful commit from an experiments branch without dragging the rest along. These three moves get you out of most git emergencies.

What you will learn

  • Undo a commit on shared history safely with git revert
  • Read git's reflog to find a commit that was reset away
  • Bring a 'lost' commit back with git cherry-pick
  • Cherry-pick a single commit from another branch without merging it
  • Tell the difference between rewriting history and adding to it

Before you start

  • Branching, Merging & Conflict Resolution first, or equivalent git basics
  • Comfortable reading git log --oneline

Tasks

  1. 01Safely revert a bad commit
  2. 02Recover a lost commit from the reflog
  3. 03Cherry-pick a single commit
  4. 04Tag the recovered state

Next in this course