merge 和 rebase 都将来自一个分支的更改集成到另一个分支中,但它们的做法不同:merge 保留历史记录,带有一个 merge 提交,而 rebase 重写历史记录以创建线性序列。理解差异以及何时使用每一个很重要。
Merge — 保留历史记录(结合)
main: A───B───C───────M ← M is a MERGE COMMIT (two parents)
\ /
feature: D───E
→ git merge feature: creates M combining the branches
✓ Preserves the actual history (shows the branch existed, when it merged)
✗ History has merge commits (can look cluttered with many merges)
