What happens to the commit history during a rebase?
When you run git rebase, the commit history is rewritten, old commits are replaced by new ones, even if the code changes are the same.
This is the most important thing to understand about rebase.
What "the history is rewritten" means
When you run rebase, Git:
- Takes the commits of your branch
- Temporarily "removes" them
- Moves the branch onto a different base commit
- Creates new commits, reapplying the changes
The old commits stop being part of the branch's history.
Visually
Before rebase:
A---B---C (main)
\
D---E (feature)After rebase:
A---B---C---D'---E' (feature)
D'andE'are the new commits- the hashes changed
- the original
DandEare no longer used
What exactly changes
| Before | After |
|---|---|
| Commit D | Commit D' |
| Commit E | Commit E' |
| Old hashes | New hashes |
| Branching history | Linear history |
Even if the code is identical, Git treats them as different commits.
Why this is dangerous for shared branches
If a branch is already:
- pushed
- used by other developers
After a rebase:
- you have a different history
- your colleagues have the old one
- Git cannot automatically reconcile them
The result is conflicts and a "broken" history.
How this is phrased at an interview
With
git rebasethe history is rewritten: commits are recreated with new hashes, which changes the sequence of the history.
And often they add:
That's why rebase should not be done on public branches.
Advantages of this approach
- a tidy, linear history
git logis easy to read- convenient before a merge
Short answer (if really brief)
git rebaserewrites the commit history: old commits are replaced by new ones with different hashes.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.