0/5

Lesson10

advanced

Rewrite History with Interactive Rebase

Goal

Tidy a branch's commits with git rebase -i before anyone else sees them.

feature/search works, but its history tells the story of a messy afternoon: a typo fixed in its own commit, a debug commit that should never be shared, and a commit called wip.

Nobody else has this branch yet, so you can rewrite it. Fold the typo fix into the commit it fixes, drop the debug commit, and give wip a real message.

Objectives

0/5
  1. Fix typo in search box is no longer a commit of its own. (Current objective)
  2. The typo fix is still in search.js. (Not started)
  3. Add debug logging is gone from feature/search. (Not started)
  4. wip is now called Highlight search matches. (Not started)
  5. feature/search reads Highlight search matches, Add search box, Initial commit. (Not started)

Your task nowStep 1 of 5

Fix typo in search box is no longer a commit of its own.

Need help?

Reference

A todo list for your commits

git rebase -i main takes the commits that are on your branch but not on main and opens them in your editor as a todo list, oldest first:

``text pick 3f1c2a9 Add search box pick 8b0d4e1 Fix typo in search box pick c27a915 Add debug logging pick 51e9f03 wip ``

You edit the list, save and close the editor, and Git replays the commits from top to bottom, doing what each line says. Change the word at the start of a line to change what happens to that commit:

  • pick — keep the commit as it is
  • reword — keep it, but write a new message (Git opens the editor again for it)
  • squash — meld it into the commit above, and combine both messages
  • fixup — meld it into the commit above, and keep only that commit's message
  • drop — leave it out (deleting the line does the same)

Lines can also be moved up or down to reorder commits.

Folding, dropping and rewording

Step 1 of 2

feature/search has four commits of its own on top of main.

Step 1 of 2. `feature/search` has four commits of its own on top of `main`.

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.