美文网首页git
rebase 与 merge 有何区别 ?

rebase 与 merge 有何区别 ?

作者: 不一样的卡梅利多 | 来源:发表于2019-06-28 18:52 被阅读0次
  • merge:两颗 tree merge 生成一个新tree
  git merge topic
 # C+G=H
before.png after.png
  • rebase: 改变基础版本,是一个patch 命令(会含有分支合并),一个 rebase 会含有多次merge 操作。
    • 情况1
git rebase master
#说明 ,已G为基点重新构建A,B,C 三个节点的tree 
#   G+A = A'  ,G+B=B', G+C=C'
#   A' 的parent 修改为G
#问题
#         1、怎么知道基点是G,怎么指定A,B,C 三个节点需要重新构建 ?
#         2、 哪些节点不见了?
before.png
after.png
  • 情况2
git rebase --onto master next topic
#说明 ,以m为基点重新构建t1,t2,t3 三个节点的tree 
#  m+t1 = t1'  ,m+t2=t2', m+t3=t3'
#   t3' 的parent 修改为m
# 问题:
#   1、怎么指定基点为m ,怎么知道t1,t2,t3 三个节点需要重新构建 ?
#   2、 哪些节点不见了?
before.png
after.png
  • 情况3
git rebase --onto topicA~5 topicA~3 topicA
# 说明 ,以E为基点重新构建H,I,J 三个节点的tree 
#   E+H = H'  ,E+I=I', E+J=J'
#   J' 的parent 修改为E
# 问题:
#      1、怎么指定基点为E ,怎么知道H,I,J 三个节点需要重新构建 ?
#      2、 哪些节点不见了?
# 注 topicA~5 :表示J(topic)节点前5个节点 为E,topicA~3 (H)
before.png
after.png
  • 问题

git rebase [--onto <newbase>] [<upstream> [<branch>]]
onto : 确认新的基点,可以缺省,默认为upstream
upstream :不能缺省,branch 的祖父节点,也是重新构建的开始节点
branch: 可以缺省,默认为当前分支。重新构建的结束节点。
例如:
git rebase --onto A B C
新基点为A ,重新构建[B,C] 范围的节点,[B,C]应该在同一分支上面,这样才能依据范围来确认哪些节点

  • 思考
    哪些场景适合merge,哪些场景适合rebase ?

相关文章

网友评论

    本文标题:rebase 与 merge 有何区别 ?

    本文链接:https://www.haomeiwen.com/subject/hunecctx.html