What does git rebase do to history?
git rebase changes the commit history, rewriting it as if the commits had been made at a different point in history.
Simply put: rebase moves commits and recreates them, making the history more linear.
What exactly happens during git rebase
Imagine this situation:
A---B---C (main)
\
D---E (feature)You are on feature and run:
git rebase mainGit:
- temporarily "removes" commits
DandE - moves the
featurepointer toC - creates new commits
D'andE'on top ofC
Result:
A---B---C---D'---E' (feature)
D' and E' are new commits with new hashes, even though the changes are the same.
How this affects history
git rebase:
- rewrites commits
- changes their hashes
- makes the history straight and readable
- removes unnecessary merge commits
Why this matters for an interview
The key phrase:
git rebasedoes not literally move commits - it recreates them.
This shows understanding, not memorization.
Interactive rebase (git rebase -i)
With interactive mode you can:
- combine commits (
squash) - change messages (
reword) - delete commits
- reorder commits
git rebase -i HEAD~3This is a classic "middle+/senior" level question.
The main rule (must be mentioned)
You must not rebase public commits.
The interview phrasing:
Rebase is safe only for local or not-yet-published branches.
rebase vs merge (very briefly)
mergekeeps the history as it isrebaserewrites the history
Short answer for an interview
git rebaserewrites the history by recreating commits on top of a different point in history, which changes their hashes and makes the history linear.
A frequent candidate mistake
Wrong: "rebase just moves the branch" Correct: it recreates the commits, it does not move them.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.