Git Rebase and Interactive Rebase: Rewriting History Safely

Master git rebase and interactive rebase — squashing, splitting, rewriting commits, and understanding when to rebase versus when to avoid it.

published: reading time: 27 min read author: Geek Workbench updated: November 17, 2026
Quick Summary

Interactive rebase reorders, combines, edits, or drops commits by replaying them with new IDs. Before rewriting history, create a rescue ref, check whether others have based work on the commits, and follow team policy. Inspect the result and coordinate any permitted remote update.

Introduction

Git rebase is one of those commands that rewards understanding but punishes carelessness. It takes your commits and replays them on top of a different base, creating a linear history instead of the branching mess that merge produces.

Interactive rebase (git rebase -i) goes further — you get to edit, reorder, squash, split, and drop commits before they’re replayed. It’s how you turn a messy series of “WIP” and “fix typo” commits into something worth showing to colleagues.

Rebase creates new commit IDs for the commits it replays. A pushed commit may be rewritten when nobody else depends on it and team policy permits. The risk is changing history that another person has already used, so check and coordinate before rewriting a shared branch.

Before You Rewrite History

Rebase creates new commit IDs. Before you edit history, save a rescue reference, inspect the commit range, and check whether anyone else depends on the commits.

  1. Check the working tree. Commit or stash any uncommitted work, then create a uniquely named rescue branch:

    git status --short --branch
    git branch backup/feature-before-rebase HEAD
  2. Fetch the intended base and inspect the commits you plan to replay:

    git fetch origin
    git log --oneline --decorate origin/main..HEAD

    Replace origin/main with the branch your team uses as the base.

  3. If the branch is published, confirm that nobody has based work on the commits and that repository policy allows the rewrite. Coordinate a migration with collaborators when needed. If the policy requires stable commit IDs, merge instead.

  4. Start the rebase only after that check. If you reach a conflict and decide not to continue, git rebase --abort returns the branch to its original pre-rebase state. Otherwise, resolve the conflict, stage the resolution, and continue with git rebase --continue.

  5. Verify the rewritten range and run the project checks before sharing it:

    git status --short --branch
    git log --oneline --graph --decorate origin/main..HEAD
    git diff --stat origin/main...HEAD

If a permitted rewrite needs a remote update, fetch and inspect the remote first. Coordinate with anyone using the branch, then use git push --force-with-lease; if the lease rejects the push, stop and review the new remote commits instead of retrying with --force. A lease is a check on the expected remote value, not a replacement for agreement. See the official git rebase and git push documentation. For recovery, read reflog recovery; for choosing an integration method, see rebase vs merge.

When to Use / When Not to Use

When to Use Rebase

These scenarios are where rebase genuinely earns its place in your workflow. The through-line: you’re cleaning up local work before it goes anywhere shared.

Keeping feature branches current is the most common use case. When main has moved ahead since you branched, rebasing your feature onto the new tip pulls in those changes without a merge commit cluttering your history. The alternative is merging main into your branch, which works but leaves a merge commit every time you sync. After a few syncs, your feature branch looks like a merge chart from a parallel universe project.

Cleaning up commit history happens before opening a pull request. Nobody wants to review a branch with commits like “WIP”, “fix typo”, “actually fix it”, “oops”. Interactive rebase lets you fold those into focused commits that tell the story of your change in logical steps. A good commit history reads like a well-written article, not a development journal.

Reordering commits matters when later commits depend on earlier ones logically. If commit C builds on work from commit B, they need to stay in that order. But if B and C are independent, you can reorder them to group related changes together. This makes the history easier to follow during review.

Splitting large commits is useful when you made one massive commit that does three different things. Rebase lets you mark it for editing, then use git reset and git add -p to carve it into separate commits — each one focused on a single logical change.

Fixing commit messages is straightforward with reword. If a commit message is vague (“fix bug”) or wrong, interactive rebase lets you stop at that commit and correct it. No need to amend when the commit you want to fix isn’t the most recent one.

When Not to Use Rebase

Rebase is a poor fit when other people may depend on the commit IDs you plan to replace. Check team policy and coordinate with collaborators first. If you cannot coordinate a shared-history rewrite, merge instead.

These cases call for a closer look at team policy, the people using the branch, and the recovery plan before choosing whether to rewrite history.

  • A branch others may have based work on — coordinate a history rewrite with them, or integrate without changing those commit IDs
  • A protected integration branch — follow its branch protection and recovery policy; do not rewrite it outside that process
  • When policy requires stable commit IDs — use the integration method the repository specifies; merge commits alone do not satisfy audit requirements
  • During active collaboration on the same branch — coordinate with your team first
  • Binary file changes — rebasing binary conflicts is painful and error-prone

Core Concepts

Rebase moves your commits to a new base. Instead of creating a merge commit, it replays each commit one by one on top of the target.


Before rebase:
main:     A ── B ── C
           \
feature:      D ── E

After git rebase main:
main:     A ── B ── C
                       \
feature:                  D' ── E'

Note that D’ and E’ are new commits with different SHAs. The original D and E still exist but are no longer referenced by the feature branch.


graph TD
    Start["Feature branch: D-E"] --> Pull["git fetch origin"]
    Pull --> Rebase["git rebase origin/main"]
    Rebase --> Replay["Replay each commit\nonto new base"]
    Replay --> Conflict{"Conflict?"}
    Conflict -->|Yes| Resolve["Resolve, git add,\ngit rebase --continue"]
    Conflict -->|No| Next{"More commits?"}
    Resolve --> Next
    Next -->|Yes| Replay
    Next -->|No| Done["Linear history:\nA-B-C-D'-E'"]

Architecture or Flow Diagram


flowchart TD
    A["Interactive Rebase:\ngit rebase -i HEAD~4"] --> B["Editor opens with todo list"]
    B --> C{"Choose action per commit"}
    C -->|pick| D["Keep commit as-is"]
    C -->|reword| E["Keep changes, edit message"]
    C -->|squash| F["Combine with previous commit"]
    C -->|fixup| G["Combine, discard message"]
    C -->|edit| H["Stop for manual edits"]
    C -->|drop| I["Remove commit entirely"]
    D --> J["Git replays commits\nin order"]
    E --> J
    F --> J
    G --> J
    H --> K["Make changes,\ngit commit --amend,\ngit rebase --continue"]
    K --> J
    I --> J
    J --> L{"Conflicts?"}
    L -->|Yes| M["Resolve, add, continue"]
    L -->|No| N["Clean linear history"]
    M --> J

Step-by-Step Guide / Deep Dive

Reference: Basic Rebase

The basic rebase operation moves your feature branch onto a new base. You point the branch at the tip of another branch — typically main or origin/main — and Git replays each of your commits on top of that new base. The commits get new SHAs because their parentage changes, but the actual diffs stay the same. This is the foundation for understanding interactive rebase: you’re not changing what changed, you’re changing where it lands.

Basic rebase handles most everyday scenarios: updating a feature branch that’s drifted from main, integrating a bug fix from one branch into another, or aligning a topic branch with a release tag. The command is straightforward; the mental model is what matters. Think of it as picking up your commits and setting them down again on a different branch.

When you rebase, Git walks through each commit in your branch from oldest to newest. For each one, it computes the diff against that commit’s parent, then applies that diff to the new base as a new commit. If there are conflicts, Git stops and asks you to resolve them before continuing. Think commit one, resolve conflicts, commit two, and so on.

The ORIG_HEAD ref is important to know about. Before rebase starts, Git records the original HEAD position in ORIG_HEAD. If the rebase goes wrong, git reset --hard ORIG_HEAD gets you back to exactly where you started. This is safer than hunting through the reflog under pressure.

One behavior that trips people up: rebasing a detached HEAD state. If you’re not on a branch when you rebase, Git treats your HEAD as an anonymous branch and the rebased commits become the new HEAD. Your commits exist but you’re not on any branch. Running git checkout -b new-branch-name after the rebase fixes this before you lose track of where your commits are.

Reference: Common Interactive Rebase Operations

Interactive rebase gives you control over the replay. Instead of blindly applying commits, Git stops at each one and asks what you want to do. You can keep it as-is, squash it into the previous commit, drop it entirely, or stop and edit it mid-replay. This is the tool for turning a messy work-in-progress history into a clean, logical sequence before you open a pull request.

The operations available in the editor — pick, squash, fixup, reword, edit, drop — each serve a distinct purpose. Pick keeps the commit unchanged. Squash and fixup both combine commits, but squash lets you edit the resulting message while fixup discards it. Reword changes the message without touching the code. Edit pauses the rebase so you can amend the commit itself. Drop removes the commit entirely. Once you’ve made your selections, Git applies them in order and your branch becomes a polished series of commits.

Basic Rebase


# Rebase current branch onto main
git switch feature-x
git rebase main

# Rebase onto a specific commit
git rebase abc1234

# Rebase onto remote branch
git rebase origin/main

# Rebase with automatic stashing (saves uncommitted work)
git rebase --autostash main

Interactive Rebase


# Interactively edit the last 4 commits
git rebase -i HEAD~4

# Interactively edit all commits since branching from main
git rebase -i main

# Editor opens with a todo list like:
# pick abc1234 Add user model
# pick def5678 Fix validation bug
# pick ghi9012 WIP: add tests
# pick jkl3456 Fix typo

Interactive Rebase Commands

Command Shortcut Effect
pick p Use commit as-is
reword r Use commit, but edit the message
edit e Stop for amending the commit
squash s Combine with previous commit, keep both messages
fixup f Combine with previous commit, discard this message
drop d Remove the commit entirely
break b Pause rebase (you decide what to do)
exec x Run a shell command after this commit
label l Label current HEAD with a name
reset t Reset HEAD to a label

Common Interactive Rebase Operations

Squashing Commits


# Before (in interactive rebase editor):
pick abc1234 Implement login
pick def5678 Fix typo
pick ghi9012 Add tests
pick jkl3456 Fix test

# After (squash fixups into the main commit):
pick abc1234 Implement login
fixup def5678 Fix typo
fixup ghi9012 Add tests
fixup jkl3456 Fix test

# Result: single commit "Implement login" with all changes combined

Splitting a Commit


# In interactive rebase, mark the commit for editing:
edit abc1234 Large monolithic commit

# When rebase stops:
git reset HEAD~1              # Unstage the commit, keep changes
git add -p                    # Interactively stage first part
git commit -m "First logical change"
git add -p                    # Stage second part
git commit -m "Second logical change"
git rebase --continue         # Continue the rebase

Rewriting Commit Messages


# Change the last commit message
git commit --amend -m "New, better message"

# Change older commit messages via interactive rebase
git rebase -i HEAD~5
# Change 'pick' to 'reword' for commits you want to edit

Production Failure Scenarios

Scenario Impact Mitigation
Rebasing shared commits Teammates may retain the old commit IDs Agree on the branch policy and coordinate any rewrite
Force push after rebase May move a shared ref away from commits others use Coordinate permitted rewrites and check the expected remote value
Losing commits during rebase Work appears to vanish Use git reflog to find and recover lost commits
Rebase conflict cascade Multiple conflicts in sequence Consider merge; or resolve carefully one at a time
Accidentally dropping commits Permanent data loss Review the todo list carefully before saving

Recovery After Bad Rebase

Rebase can go wrong even when you’re being careful. Conflicts might pile up until resolving them becomes a chore. You might finish and realize the result isn’t what you wanted. Or you force-push before noticing a mistake, and now remote is wrong too. Git gives you exits at every stage — you just need to pick the right one.

Three scenarios come up most often: a rebase that’s stuck mid-conflict, a completed rebase that turned out wrong, and a force-push that’s already on remote.


# If rebase is in progress
git rebase --abort

# If rebase completed but result is wrong
git reflog
# Find the pre-rebase HEAD position
git reset --hard ORIG_HEAD

# If you already force-pushed
# Team members should reset to the correct remote
git fetch origin
git reset --hard origin/main

Trade-off Analysis

Approach Pros Cons
Rebase Linear view, can help follow commit sequence Replayed commits get new IDs; coordinate if others use them
Merge Keeps existing commit IDs and records an integration point Adds a merge commit; its value depends on the workflow
Squash Single clean commit Loses individual commit context
Fixup Clean history, no extra messages Hides the fact that fixes were needed
Edit commits Perfect commit granularity Time-consuming, requires careful planning
Drop commits Removes mistakes permanently Loses work; use reflog to recover

Implementation Snippets


# Complete workflow: clean up feature branch before PR
git fetch origin
git rebase origin/main          # Get current with main
git rebase -i HEAD~8            # Clean up commit history
# squash fixups, reword messages, drop WIP commits
git push --force-with-lease     # After coordination; confirms the expected remote value

# Auto-squash all fixup commits
git rebase -i --autosquash HEAD~10

# Rebase with exec to run tests after each commit
git rebase -i -x "npm test" HEAD~5

# Lease check; coordinate and confirm the expected remote value first
git push --force-with-lease origin feature-x

# Rebase only unpushed commits
git rebase -i @{upstream}

Observability Checklist

  • Logs: Record rebase operations in CI logs for audit trails
  • Metrics: Track rebase frequency vs merge frequency per team
  • Alerts: Alert on force pushes to protected branches
  • Traces: Link rebased commits to original PR numbers
  • Dashboards: Display commit hygiene scores (squash rate, message quality)

Security & Compliance Considerations

Rebasing creates new commit IDs and committer dates. That can make existing links to reviews, builds, or deployment records harder to follow, depending on how the repository retains them. A merge keeps the original commit objects reachable, but no history shape alone provides a complete audit record; check the repository’s retention and signing requirements.

  • Check repository policy before rewriting reviewed or released commits
  • Block force pushes to protected branches through platform settings
  • Rebase creates new commits, so verify or re-sign them when signature policy requires it; --signoff adds a trailer, not a cryptographic signature
  • Document the team’s rebase and recovery process

Common Pitfalls / Anti-Patterns

  • Rewriting commits others depend on — creates divergent histories that collaborators must reconcile
  • Squashing everything — losing all commit granularity makes bisecting impossible
  • Forgetting to rebase before PR — reviewers see stale code and outdated conflicts
  • Assuming a lease replaces coordination — confirm the expected remote value and agree on a shared-branch rewrite
  • Dropping commits accidentally — always review the interactive rebase todo list
  • Rebasing merge commits — creates duplicated history; merge commits should stay merged

Quick Recap Checklist

  • Rebase moves commits to a new base, creating new commit SHAs
  • Use git rebase -i to squash, split, reorder, and edit commits
  • Check who depends on published commits and follow the team’s rewrite policy
  • Coordinate permitted rewrites and check the expected remote value before updating
  • Recover lost commits with git reflog
  • Abort a bad rebase with git rebase --abort
  • Use --autosquash to automatically combine fixup commits
  • Run tests after rebase to verify nothing broke

Production Failure: Rebasing Shared Branches

Scenario: A developer rebases the develop branch after it has been pushed and pulled by 5 team members. The rebase rewrites all commit SHAs. Each team member now has a divergent history. When they push, Git rejects their commits as “non-fast-forward.” When they force-push to fix it, they overwrite each other’s work.

Impact: Team-wide history divergence, lost commits, hours of manual recovery, broken CI pipelines, and eroded trust in Git workflows.

Mitigation:

  • Ask the team before rewriting a branch that others may have based work on
  • Protect shared branches (main, develop) with force-push restrictions
  • Follow the repository’s merge or rebase policy for integration
  • If everyone agrees to rewrite a shared feature branch, coordinate timing and recovery steps
  • Use git reflog to recover lost commits after accidental rebases

# Block force pushes on protected branches (GitHub)
gh api repos/{owner}/{repo}/branches/main/protection \
  --method PUT \
  --field enforce_admins=true \
  --field required_pull_request_reviews='{"required_approving_review_count":1}'

# Recover from accidental shared rebase
git reflog
git reset --hard ORIG_HEAD  # restore pre-rebase state
git fetch origin
git reset --hard origin/develop  # align with remote

Trade-offs: Rebase vs Merge

Dimension Rebase Merge
History cleanliness Linear, easy to read Non-linear, shows true integration points
Collaboration cost Coordinate when collaborators depend on old IDs Coordinate integration and resolve conflicts
Recovery difficulty Hard — rewritten SHAs, reflog needed Easy — revert the merge commit
Bisect friendliness Excellent — single path Good — but merge commits add noise
Review records New IDs may require review links to be updated Existing commit IDs remain available
Conflict resolution Per commit — may resolve same conflict multiple times Once — all conflicts resolved together
Team size impact Depends on who uses the branch and team policy Depends on integration and review policy
Best use case Local feature branches before PR Shared branches, release integration

Rebase and Compliance Records

Rebase creates new commit IDs and committer dates, which can affect links between commits and a repository’s review, build, and deployment records. The impact depends on how the hosting platform and surrounding systems retain those records. A merge keeps existing commit IDs reachable, but that alone does not establish compliance; teams should follow their repository’s signing, retention, and approval rules.


# Preserve signoff during rebase (but not GPG signatures)
git rebase --signoff main

# Verify commit signatures after rebase
git log --show-signature

# Check if any commits lost their signatures
git log --format="%H %G?" | grep -v "^.* [GU]"

Best practice: Follow the repository’s policy for production and regulated branches. If a rewrite is allowed, preserve required review and deployment records and verify signatures on the new commits.

Rebase Architecture: Commit History Linearization

Before Rebase

Imagine main has three commits (A, B, C) and your feature branch diverged at A with its own commits D and E. Both branches have moved forward independently since the split. Your feature is still based on an old version of main — it’s drifted, and the longer you wait, the worse the divergence.

In the diagram below, the dashed lines show branch relationships, not actual commit ancestry. Commit D’s parent is A, not C. The branches split at that point and have never been synchronized.


graph TD
    A1["A"] --> B1["B"]
    B1 --> C1["C"]
    A1 --> D1["D"]
    D1 --> E1["E"]
    C1 -. "main" .-> C1
    E1 -. "feature" .-> E1

    classDef commit color:#00fff9
    class A1,B1,C1,D1,E1 commit

After git rebase main

After running git rebase main, the feature branch’s commits are replayed on top of commit C, the current tip of main. But this creates entirely new commits. D’ is based on C and carries D’s changes. E’ is based on D’ and carries E’s changes. The original D and E still exist in your repository, but nothing points to them anymore. They’re orphaned.

D’ and E’ are new commits with new SHAs, even when their changes match D and E. If a teammate still has D or E in their branch, rewriting and force-pushing can leave the two branches with different histories. Coordinate first so collaborators know whether to update their branches, merge the rewritten work, or keep the original commits.

After the rebase, the feature branch sits cleanly on top of main with no merge commits and a straight line of commits from A through E’.


graph TD
    A2["A"] --> B2["B"]
    B2 --> C2["C"]
    C2 --> D2["D' (new SHA)"]
    D2 --> E2["E' (new SHA)"]
    C2 -. "main" .-> C2
    E2 -. "feature" .-> E2

    classDef commit color:#00fff9
    class A2,B2,C2,D2,E2 commit

D’ and E’ are new commits with different SHAs. The feature branch no longer points to the original D and E, though a local reflog may retain a recovery reference for a time. If collaborators still use D or E, agree on how they will update before publishing the rewritten branch.

Interview Questions

1. What is the difference between git merge and git rebase?

git merge can create a merge commit that connects two parent histories while keeping their existing commit IDs. git rebase replays commits onto a new base, creating new IDs and a linear view. The choice affects the commit graph; review records and repository policy determine what history the team retains.

2. What is the difference between squash and fixup in interactive rebase?

Both combine a commit with the previous one. squash keeps both commit messages and opens an editor to combine them. fixup discards the squashed commit's message entirely, keeping only the previous commit's message. Use fixup for typo fixes and squash when you want to preserve context.

3. Why should you coordinate before rebasing commits on a shared branch?

Rebase replays commits with new IDs. If teammates based work on the old commits, their branches can diverge and need reconciliation. Before rewriting a published branch, check who depends on it and follow team policy; a coordinated rewrite can work when everyone using the branch is prepared to update.

4. How do you split a single large commit into multiple smaller commits?

Use git rebase -i and mark the commit as edit. When the rebase stops, run git reset HEAD~1 to unstage the commit while keeping changes in the working directory. Then use git add -p to selectively stage hunks for the first commit, commit it, repeat for subsequent commits, then git rebase --continue.

5. What does git push --force-with-lease do and why is it safer than --force?

--force-with-lease asks Git to update the remote only if its current value matches the expected value, often the local remote-tracking ref. If the remote has moved, the push is rejected. Coordinate first with anyone using the branch, and remember that background fetches can update the tracking ref; an explicit expected SHA provides a clearer check. --force does not make that comparison.

6. What does git rebase --onto do and when would you use it?

--onto rebases a range of commits onto a different branch, without requiring the source branch to be based on the target. The syntax is git rebase --onto <newbase> <upstream> <branch>. Use cases include: moving a feature branch that was branched from an old release to a new one, extracting commits from one branch to apply elsewhere, and correcting a mistaken branch base.

7. How do you resolve conflicts during an interactive rebase?

When a conflict occurs during rebase, Git marks the conflicting files. Resolve each conflict manually, then run git add <resolved-file> to stage the resolution. Do not run git commit. After staging all conflicts, continue the rebase with git rebase --continue. To abandon the entire rebase and return to the original state, use git rebase --abort.

8. What is the difference between git rebase -i and git rebase --autosquash?

git rebase -i opens an editor for manual control over each commit (pick, squash, fixup, edit, drop, etc.). git rebase --autosquash automatically squashes commits prefixed with fixup! or squash! when combined with interactive rebase (git rebase -i --autosquash HEAD~n). --autosquash saves time by not requiring manual ordering of fixup commits in the todo list.

9. When would you choose git merge over git rebase in a team workflow?

Merge keeps existing commit IDs and records an integration point, which can help when several developers share a branch or a release needs visible integration history. Rebase can be useful for a private feature branch when repository policy allows it and nobody depends on the old IDs. Neither method alone guarantees an audit record; choose according to team policy and the records your review and release process retains.

10. How does git reflog help recover from a bad rebase?

git reflog records every HEAD movement. After a bad rebase, run git reflog to find the commit hash before the rebase (shown as HEAD@{n} before the rebase operation). Then reset to that commit with git reset --hard HEAD@{n} or git reset --hard <hash>. Reflog entries are typically kept for 90 days by default.

11. What is the difference between git rebase --abort, --continue, and --skip?

--abort cancels the rebase entirely and returns the branch to its pre-rebase state. --continue resumes the rebase after you have resolved conflicts and staged the changes. --skip abandons the current commit being applied and moves on to the next one — useful when a commit's changes are no longer needed or conflict resolution is impractical.

12. Can you rebase merge commits? What happens if you do?

Technically yes (git rebase -p or manually), but it creates duplicated history and is not recommended. When you rebase a merge commit, Git replays the merged commits individually rather than preserving the merge as a single unit. This results in duplicate commits in the target branch. Merge commits should remain merges — rebasing them defeats the purpose of the merge and breaks history integrity.

13. How does git cherry-pick differ from git rebase for applying commits?

Cherry-pick applies specific individual commits from one branch to another, creating new commits with new SHAs for each picked commit. Rebase replays a range of consecutive commits onto a new base, preserving their relative order and relationships. Cherry-pick is selective; rebase is wholesale. Before rewriting or adding commits to a shared branch, check team policy and coordinate with anyone who may depend on the current history.

14. What does git rebase --signoff do, and when is it important?

--signoff adds a Signed-off-by trailer to each rebased commit, similar to git commit --signoff. This is important in environments requiring Developer Certificate of Origin (DCO) compliance, such as Linux kernel development. Note that --signoff does not preserve GPG signatures — rebasing inherently changes commit SHAs, which breaks GPG verification.

15. What is an "upstream" branch and how does it affect git rebase?

The upstream branch is the tracked reference branch (set via git branch --set-upstream-to or git config branch.<name>.remote). git rebase (without arguments) rebases the current branch against its upstream. The @{upstream} or @{u} shorthand refers to this branch. For example, git rebase -i @{upstream} rebases only unpushed commits.

16. How does interactive rebase handle commits that are identical or empty after modifications?

Git automatically marks empty commits (no net changes) as droped during rebase. If two commits produce identical diffs, the second one becomes empty and is dropped. Commits that become invalid (e.g., due to conflict resolution making their changes redundant) are also silently dropped unless you explicitly prevent it. Use --keep-empty to preserve empty commits intentionally.

17. What are the implications of rebasing in a CI/CD pipeline?

In CI/CD: rebasing creates new SHAs, so any pipeline triggered by commit SHA will run again for rebased commits. Force-pushing may trigger security alerts or require additional permissions. Pipelines relying on commit-based caching may need invalidation. Signed commits may break verification. Best practice: rebase locally before pushing, not after, to minimize pipeline noise and security concerns.

18. How do you use git rebase -x (exec) to validate each commit during rebase?

git rebase -x "npm test" runs the specified command after applying each commit during rebase. If the command fails (non-zero exit), the rebase stops at that commit so you can fix the issue. This is useful for ensuring each commit in a series is independently valid — for example, running tests, linters, or build steps. Example: git rebase -i -x "npm test" HEAD~5.

19. What is the difference between a "soft reset" and a "hard reset" in the context of rebase recovery?

A soft reset (git reset --soft) moves HEAD to the target commit but preserves changes in the index and working directory. A hard reset (git reset --hard) resets everything — HEAD, index, and working directory — to the target state. During rebase recovery, --hard is typically used with ORIG_HEAD or a reflog entry to completely restore the pre-rebase state.

20. How does git bisect work with rebased branches?

git bisect performs a binary search through commit history to find a buggy commit. After rebase, the rebased commits have new SHAs but still contain the same changes, so bisect can still find bugs — it will identify the new commit hashes rather than the originals. Ensure you have tested both pre-rebase and post-rebase states when using bisect on a branch that was recently rebased.

Further Reading

Conclusion

Interactive rebase is the difference between a history that happened and a history that tells a story. Used responsibly on local and feature branches only, it’s one of Git’s most powerful cleanup tools. Squash, reorder, and edit commits before sharing — your collaborators will thank you.

Category

Related Posts

Rebase vs Merge: When to Use Each in Git

Decision framework for choosing between git rebase and git merge. Understand trade-offs, team conventions, history implications, and production best practices.

#git #version-control #rebase

Centralized vs Distributed VCS: Team Trade-offs

Compare centralized and distributed version control by offline work, repository size, access control, branching, review, and migration effort.

#git #version-control #svn

Automated Changelog Generation

Generate release notes from structured commits, choose a release policy, and add changelog generation to CI without treating every merge as a release.

#git #version-control #changelog