#git-merge-vs-rebase-history
How does merge differ from rebase in terms of history?
Что отвечать
`merge` keeps history as it is. The two trunks stay, and a merge commit appears with two parents. `rebase` takes the commits from your branch, detaches them, and replays them on top of the target branch. You get a linear history, but **with new SHAs**, because the parent of each commit changed. Merge is safe and rewrites nothing. Rebase buys you a clean history at the cost of rewritten commits.
Что хотят услышать
The candidate should: - say that rebase rewrites commit SHAs while merge does not - explain why a linear history is easier for `git log`, `bisect`, and PR review, while a merge commit "eats" context and reads poorly - say when merge is better: long-lived feature branches where the history needs to show "a parallel stream was developed here" - say when rebase is better: pull in fresh main before a PR, sync a local branch without a merge commit - mention that large teams often adopt rebase locally plus a merge when the PR lands (see squash-merge below)
Подводные камни
- ✗ Saying "rebase is always better than merge". It is not. On a shared branch, rebase breaks other people's copies
- ✗ Thinking a conflict-free merge is always a fast-forward. Not always. If main moved ahead, you get a three-way merge
- ✗ Confusing `git rebase main` (replay my commits on top of main) with `git rebase --onto` (move an arbitrary range)
Follow-up
- ? What happens to commit SHAs after `git rebase main` on a feature branch?
- ? How do you undo a botched rebase?
- ? How does a three-way merge differ from a fast-forward?
Глубина в базе знаний