Skip to content
Lab 3 of 3

Rewriting History: Rebase & Bisect

Clean a messy branch before sharing it: squash work-in-progress commits, rebase a feature onto an updated main for linear history, then use git bisect to pinpoint the exact commit that introduced a bug.
  • Advanced
  • 45 min
  • Git
  • Rebase
  • bisect
  • Version control

Overview

Two of git's most powerful tools scare people off because they rewrite history — but on your own unshared work they're how professionals keep history readable and hunt down regressions.

In ~/src you'll squash three messy wip: commits into one, rebase a feature branch onto an advanced main so its history is linear, then let git bisect binary-search a ten-commit history to find precisely which commit broke a passing test — in a handful of steps instead of reading every diff. You'll finish by fixing the regression bisect found.

What you will learn

  • Squash several commits into one with an interactive rebase
  • Rebase a feature branch onto an updated main for linear history
  • Automate a regression hunt with git bisect run
  • Identify the exact commit that introduced a bug
  • Fix the regression and confirm the test passes

Before you start

  • History Surgery first, or solid git branching/commit experience
  • You can read a few lines of Python
  • You understand a commit has a parent (history is a chain)

Tasks

  1. 01Squash the WIP commits
  2. 02Rebase the feature branch
  3. 03Bisect the regression
  4. 04Fix the regression