0Pricing
DevOps Bootcamp · Lesson

Interactive Rebasing for History

Use interactive rebase to rewrite commit history, squash commits, reorder, or edit messages before pushing.

Interactive Rebasing for History is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Meet Interactive Rebase

Welcome to a powerful Git tool: interactive rebase! It allows you to rewrite your project's commit history before sharing it with others.

Think of it as a time machine for your commits, letting you clean up, combine, or reorder changes to create a clear, linear story of your work.

Why Clean Up History?

Why would you want to rewrite history?

  • Clarity: Make your project's commit log easy to read and understand.
  • Conciseness: Combine small, incremental commits into a single, meaningful change.
  • Debugging: A clean history helps when using tools like git bisect to find where a bug was introduced.
  • Better Pull Requests: Present a polished set of changes to collaborators.

Initiating Interactive Rebase

To start an interactive rebase, you'll use the git rebase -i command. You need to specify how far back you want to go.

For example, to rebase the last 3 commits on your current branch, you'd use:

git rebase -i HEAD~3

This opens an editor showing your last 3 commits and available commands.

The Rebase Editor Commands

When you start an interactive rebase, Git opens a text editor with a list of commits and instructions. Each commit starts with a command:

  • pick: Use the commit as is.
  • reword: Use the commit, but edit its message.
  • edit: Use the commit, but pause to amend changes.
  • squash: Combine with the previous commit, merging messages.
  • fixup: Combine with the previous commit, discarding this commit's message.
  • drop: Remove the commit entirely.

Example: Rewording a Commit

Let's say you made a typo in a commit message. You can use reword to fix it. Change pick to reword next to the commit you want to change:

pick 5a6b7c8 Add new feature
pick 1d2e3f4 Fix typo in docs
reword 9g0h1i2 Implement login screen

After saving and closing the editor, Git will prompt you to edit the message for the 9g0h1i2 commit.

Example: Squashing Commits

Often, you make several small, related commits that could be one. Use squash to combine them.

pick a1b2c3d Initial feature commit
squash e4f5g6h Add more details
fixup i7j8k9l Fix small bug

Here, e4f5g6h will merge into a1b2c3d, combining their messages. i7j8k9l will also merge into a1b2c3d, but its message will be discarded (fixup).

Example: Dropping Commits

If you have an experimental commit you no longer need, you can simply drop it from history. Just change pick to drop or delete the line entirely:

pick 1122334 Initial setup
drop 5566778 Test experimental feature
pick 9900112 Add user authentication

After saving, the commit 5566778 will be completely removed from your branch's history.

Example: Reordering Commits

You can also change the order of commits. Simply cut and paste lines in the editor to rearrange them. Git will apply the changes in the new order.

Original order:

pick abcdef1 Add feature A
pick 1234567 Add feature B

Reordered:

pick 1234567 Add feature B
pick abcdef1 Add feature A

Be cautious, as reordering might introduce conflicts if commits depend on each other.

The Golden Rule: Don't Rebase Shared History!

This is crucial: Never rebase commits that have already been pushed to a shared remote repository (like GitHub or GitLab) and might have been pulled by others.

Rebasing rewrites commit IDs. If others have based their work on the original commits, your rebased commits will appear as a completely different history, causing major conflicts and confusion for everyone involved.

Only rebase commits that exist solely on your local branch!

Rebase Command Check

You have three commits: A (Initial), B (Minor fix), C (Refactor). You want to combine B into A, keeping A's original message, and then keep C as is. Which commands would you use in the interactive rebase editor (from oldest to newest)?

Interactive Rebase Recap

You've learned about the powerful git rebase -i command!

  • It allows you to rewrite your local commit history.
  • You can reword messages, squash or fixup commits, drop unwanted changes, and even reorder commits.
  • Always remember the golden rule: NEVER rebase commits that have already been pushed to a shared remote.

Mastering interactive rebase helps maintain a clean, understandable project history!

Frequently asked questions

Is the “Interactive Rebasing for History” lesson free?

Yes — the full text of “Interactive Rebasing for History” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.

What will I learn in “Interactive Rebasing for History”?

Use interactive rebase to rewrite commit history, squash commits, reorder, or edit messages before pushing. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start DevOps Bootcamp?

No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Interactive Rebasing for History” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this DevOps Bootcamp lesson?

Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Manual Merge Conflict Resolution
  2. Interactive Rebasing for History
  3. Cherry-picking Commits
  4. Using Git Rerere to Reuse Conflict Resolutions
← Back to DevOps Bootcamp