Skip to content

Rearranging Your History

Cherry-Picking (Hand-Picking Saves)

Imagine you did a bunch of work on a side branch, but you only want to copy one or two specific saves over to your main branch, not the whole thing. This is called cherry-picking.

# Grabs the exact saves labeled c2 and c4 and pastes them onto your current branch
git cherry-pick c2 c4

Interactive Rebase (The Ultimate Editor)

If you want to clean up your save history before showing it to others, you can use an interactive rebase. It opens a menu that lets you reorder your saves, delete accidental files, or combine small saves into one big one.

# Look at and edit the last 4 saves you made
git rebase -i HEAD~4

Fixing Tricky Situations:

Cleaning Up Messy Debug Commits

The Problem: You fixed a bug on a side branch, but along the way, you made 5 messy saves full of temporary "print" or "test" statements. You want the bug fix on main, but you don't want all that clutter.

The Solution: You can use Interactive Rebase to delete or combine the messy test saves first, or use Cherry-pick to grab just the final, clean fix save and paste it onto main.

Changing a Save Deep in the Past If you realize you made a typo two saves ago, you can juggle your timeline:

Use git rebase -i to temporarily swap the order of your saves so the mistake is on top.

Fix the typo and use git commit --amend to update that save.

Use git rebase -i again to put the saves back in their original order.

Shortcut Method (Using Cherry-Pick):

git checkout main
git cherry-pick C2
git commit --amend       # Fix the typo here
git cherry-pick C3       # Put the next save back on top