> For the complete documentation index, see [llms.txt](https://bvct1742.gitbook.io/one-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://bvct1742.gitbook.io/one-book/knowledge/git/git-rebase-he-git-merge-de-qu-bie.md).

# git rebase 和 git merge 的区别

> `git rebase` 和 `git merge` 一样都是用于从一个分支获取并且合并到当前分支

#### git merge

* 将分支切换到 `master` 上去：`git checkout master`
* 将分支 `feature` 合并到当前分支（即 `master` 分支）上：`git merge feature`

特点

* 只处理一次冲突
* 引入了一次合并的历史记录，合并后的所有 `commit` 会按照提交时间从旧到新排列
* 所有的过程信息更多，可能会提高之后查找问题的难度

#### git rebase

* 改变当前分支从 `master` 上拉出分支的位置
* 没有多余的合并历史的记录，且合并后的 `commit` 顺序不一定按照 `commit` 的提交时间排列
* 可能会多次解决同一个地方的冲突（有 `squash` 来解决）
* 更清爽一些，`master` 分支上每个 `commit` 点都是相对独立完整的功能单元

#### 总结

当需要保留详细的合并信息的时候建议使用 `git merge`，特别是需要将分支合并进入 `master` 分支时；当发现自己修改某个功能时，频繁进行了 `git commit` 提交时，发现其实过多的提交信息没有必要时，可以尝试 `git rebase`。
