• git rebase的基本使用


    git rebase:改变基底。下面举例说明git rebase的作用:

    A---B   remote master
    A---B   local master
    
    • 1
    • 2

    如上图,首先通过git pull同步远程的master分支。
    然后我新建了一个feature分支用于开发相关的功能,如下图:

    A---B   remote master
    A---B   local master
    	 \
    	  C---D   feature
    
    • 1
    • 2
    • 3
    • 4

    我在feature上实现功能时,有人在远程上传了新的提交,如下:

    A---B---E   remote master
    A---B   local master
    	 \
    	  C---D   feature
    
    • 1
    • 2
    • 3
    • 4

    此时如果我需要合并feature到master,我需要回到master分支去做git pull操作,从而同步远程的master,如下:

    A---B---E   remote master
    A---B---E   local master
    	 \
    	  C---D   feature
    
    • 1
    • 2
    • 3
    • 4

    然后我回到feature上,使用git rebase master改变feature的基底,结果如下:

    A---B---E   remote master
    A---B---E   local master
    		 \
    	 	  C---D   feature
    
    • 1
    • 2
    • 3
    • 4

    将分支feature的基底改为E的过程中,会进行冲突检查。假设C和E有冲突,处理冲突的过程如下:

    1.对冲突文件进行修改
    2.git add .
    3.git commit -m"处理C和E的冲突"
    4.git rebase --continue # 这个命令表示继续进行rebase,如果上面刚提交的"处理C和E的冲突"与D有冲突,那么就会回到步骤1
    
    • 1
    • 2
    • 3
    • 4

    在进行完rebase操作以后,最后我们一般在master中执行git merge feature来实现合并,结果如下:

    A---B---E   remote master
    A---B---E--------F   local master
    		 \     /
    	 	  C---D   feature
    
    • 1
    • 2
    • 3
    • 4

    上面的这个使用merge和rebase的过程时官网推荐的,即
    第一步,次级分支rebase main
    第二步, main merge次级分支

    git rebase -i master 可以进行交互式的rebase操作【暂时不学,以后再说】

    参考:
    https://www.bilibili.com/video/BV19B4y1u7vm
    https://www.bilibili.com/video/BV1Xb4y1773F
    https://www.csdn.net/tags/Mtjacg3sMDMyMjUtYmxvZwO0O0OO0O0O.html

  • 相关阅读:
    tomcat8 后台getshell漏洞复现
    Node.js(6)-node的web编程
    【MyBatis】MyBatis是什么?能干什么?一篇学习MyBatis,知识点详细解释,实例演示
    静态成员函数与回调函数
    《Orange‘s 一个操作系统的实现》第六章
    CSS垂直居中的方法
    LaTex编写伪代码,并实现根据所在章编号(连字符),例如算法1-1
    进程环境~
    Linux内核netLink套接字
    数据集划分——train_test_split函数使用说明
  • 原文地址:https://blog.csdn.net/qq_42775938/article/details/125420838