zoukankan      html  css  js  c++  java
  • what's is the different between git rebase and git meger.

    1. build a environment of the test

    first of all . create the branch like below

    D:\gitTest\Download4Http>git branch
      Bensonhe-dev
      change-branch
      dev
      master
      merge-branch
    * rebase-branch

    image

    then change something on change-branch and commit it as node “changeA” .

    and change  it again and commit as node “changB”

    the same way for the merge-branch and rebase-branch

    D:\gitTest\Download4Http>git branch
      Bensonhe-dev
      change-branch
      dev
      master
      merge-branch
    * rebase-branch

    D:\gitTest\Download4Http>git checkout change-branch
    Switched to branch 'change-branch'

    D:\gitTest\Download4Http>git commit -a -m "changeA"
    [change-branch 0672bb4] changeA
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git commit -a -m "changeB"
    [change-branch 97d5ac4] changeB
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git checkout merge-branch
    Switched to branch 'merge-branch'

    D:\gitTest\Download4Http>git commit -a -m"mergeA"
    [merge-branch d29ddb1] mergeA
    1 file changed, 2 insertions(+), 1 deletion(-)

    D:\gitTest\Download4Http>git commit -a -m"mergeB"
    [merge-branch 76d4732] mergeB
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git checkout rebase-branch
    Switched to branch 'rebase-branch'

    D:\gitTest\Download4Http>git commit -a -m "rebaseA"
    [rebase-branch c213fec] rebaseA
    1 file changed, 2 insertions(+), 1 deletion(-)

    D:\gitTest\Download4Http>git commit -a -m "rebaseB"
    [rebase-branch 6cd92c2] rebaseB
    1 file changed, 1 insertion(+), 1 deletion(-)

    after the finish. the node tree should be like  this

    image

    2. Test for it

    change branch on the rebase-branch

    use the command git rebase change-branch. and show the log

    image

    you can find have 4 commit nodes. the branch tree like this

    image

    use the command git merge change-branch. and show the log

    image

    you can find the git will create a new commit node . total have 5 commit nodes. the branch tree like this

    image

    3. when should I use git rebase?  when should I use git merge?

    below  show the how to fix the 2 conflict when you merge different branch

    D:\gitTest\Download4Http>git branch
      Bensonhe-dev
      change-branch
      dev
      master
    * merge-branch
      rebase-branch

    D:\gitTest\Download4Http>git checkout change-branch
    Switched to branch 'change-branch'

    D:\gitTest\Download4Http>git commit -a -m "changeConflictA"
    [change-branch d3b8845] changeConflictA
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git commit -a -m "changeConflictB"
    [change-branch 76b70ba] changeConflictB
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git checkout merge-branch
    Switched to branch 'merge-branch'

    D:\gitTest\Download4Http>git commit -a -m "mergeConflictA"
    [merge-branch 4ad0e13] mergeConflictA
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git commit -a -m "mergeConflictB"
    [merge-branch 5c1a613] mergeConflictB
    1 file changed, 1 insertion(+), 1 deletion(-)

    D:\gitTest\Download4Http>git merge change-change
    fatal: 'change-change' does not point to a commit

    D:\gitTest\Download4Http>git merge change-branch
    Auto-merging README.md
    CONFLICT (content): Merge conflict in README.md
    Automatic merge failed; fix conflicts and then commit the result.

    D:\gitTest\Download4Http>git commit -a -m "fix the merge Conflict"
    [merge-branch d490c8b] fix the merge Conflict

    D:\gitTest\Download4Http>git merge change-branch
    Already up-to-date.

    below  show the how to fix the 2 conflict when you rebase different branch

    the rebase if  have conflict is default with merge.

    use reabase ,the git will apply commit node one by one.like this

    image

    if the git find conflict . it will skip branch (no branch)  for your merge the changes

     image

    if you merge one by yourself . use git add to add index for the changes.and use git rebase – –continue to continue rebase

    the git will aplly next node .

    image

    until you finish the all conflict

    image

    the different from git merge.  the git merge will apply all the changes  by one time.

    so I think if have many commit nodes . you had better use git merge.

    if only few commit node .you had better use the git rebase. it can loss the commit nodes.it is better for you to manager the branch

    if you have any question .you can send email to me .my email adress is qing878@gmail.com ,the skype is qing878

    thanks

    Benson

    文章是我原创,用英文写只为了提高下英语水平,水平很烂勿喷啊,呵呵,欢迎交流,我标明啊,编者别删拉

  • 相关阅读:
    IM的扫码登录功能如何实现?一文搞懂主流的扫码登录技术原理
    IM“扫一扫”功能很好做?看看微信“扫一扫识物”的完整技术实现
    2020年了,Android后台保活还有戏吗?看我如何优雅的实现!
    P2P技术详解(三):P2P中的NAT穿越(打洞)方案详解(进阶分析篇)
    微信团队分享:极致优化,iOS版微信编译速度3倍提升的实践总结
    史上最通俗,彻底搞懂字符乱码问题的本质
    你知道,HTTPS用的是对称加密还是非对称加密?
    IM开发基础知识补课(七):主流移动端账号登录方式的原理及设计思路
    面视必备,史上最通俗计算机网络分层详解
    阿里钉钉技术分享:企业级IM王者——钉钉在后端架构上的过人之处
  • 原文地址:https://www.cnblogs.com/springsource/p/2828719.html
Copyright © 2011-2022 走看看