git rebase 和 git merge 区别

一直在使用这两个命令,但对两者之间的细节没有在意过,今天受启发,具体的研究一下 。

  • 在合并分支时,git rebase 会将分支的 commit 信息一并合如 master 分支 , 而 git merge 不会,它会在主分支外保留其他分支的 commit 信息 。
git rebase 和 git merge 区别_第1张图片
rebase 和 merge 的提交历史图
  • 将分支删除后 ,两种情况下的 commit 信息都不会消失 , 但是 git merge 会留下合并分支的记录 。
git rebase 和 git merge 区别_第2张图片
rebase 和 merge 删除分支后的区别

个人爱好: 为保证代码提交历史的条理性,建议使用 git rebase 操作 。

git rebase 使用步骤

分支 master 和 branch (当前分支 master)

git rebase branch

编辑过程中存在冲突,解决完冲突后,执行:
git add xx
继续变基
git rebase --continue
查看代码树
git log --graph

你可能感兴趣的:(git rebase 和 git merge 区别)