遇一山,过一山,处处有风景;只要勇敢向前,一路尽是繁花盛开。 | (点击查看→)【测试干货】python/java自动化、持续集成、性能、测开、简历、笔试面试等

Git必知必会基础(13):远程冲突(conflicts)解决--rebase

 

 

本系列汇总,请查看这里https://www.cnblogs.com/uncleyong/p/10854115.html

演示场景

虽然每次合并代码前会先把分支更新到最新,但是在你pull后到push前这段时间,可能其它小伙伴又push了,那么你的分支就不是最新的了

在push的时候就会失败,比如遇到这种提示信息:

To gitee.com:qzcsbj/pytest_apiautotest.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'gitee.com:qzcsbj/pytest_apiautotest.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

本篇我们演示这种场景,并用rebase解决冲突。

git pull --rebase = git fetch + git rebase

 

数据准备

重新克隆

  

日志

 

远程分支qzcsbj.txt内容

 

commit id

 

其他人提交

模拟其他人对master做了提交:直接gitee上修改文件并提交

 

新的commit id

 

本地提交

本地分支修改qzcsbj.txt内容为:

 

添加到暂存区

 

提交到本地仓库

 

推送到远程仓库,报错

 

To gitee.com:qzcsbj/pytest_apiautotest.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'gitee.com:qzcsbj/pytest_apiautotest.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

大概意思是:远程仓库别人推送的内容,我们本地没有

 

日志

 

 

解决冲突

拉取最新master分支,并rebase到该分支

git pull --rebase origin master

下面做了自动合并;当前在远程分支版本516f1a4

 

日志:git log中少了5344be2

 

git status

 

查看文件内容

 

内容修改为:

 

状态和日志

 

添加到暂存区

 

日志

 

git rebase --continue,提示不能提交暂存的修改

 

error: Terminal is dumb, but EDITOR unset,意思是终端无响应,未设置EDITOR

https://stackoverflow.com/questions/64276769/git-rebase-continue-without-opening-the-editor/64350016#64350016

 

方法一:换用git bash

说明,方法一的截图和前面非同一个demo,这里仅仅为了演示;续接上面数据,我们会用方法二继续演示

执行git rebase --continue后,直接进入命令模式,显示类似如下的内容,也就是说会让修改提交信息

输入i进入编辑模式,修改log信息

 

修改完成后,esc退出编辑模式,:wq保存退出,然后会显示如下信息,说明生成了一个新的commit id(7e80ee6)、变基成功并更新refs/heads/master

此时直接push就可以成功

 

下面是日志

 

 

 

方法二:执行commit

如果终端未设置EDITOR,我们也可以自己commit 

commit,颜色变成白色了,生成了一个新的commit id

 

状态和日志:当前 master分支在516f1a4,HEAD在30aa53a

 

git rebase --continue,master rebase到HEAD

 

 

状态、日志:git log中,少了5344be2

 

git push

 

push成功后,远程分支内容

 

commit id

 

查看分支合并图

git log --graph,是一条直线

 

 

git log --graph --oneline

 

【bak】

 

posted @ 2024-01-21 19:35  全栈测试笔记  阅读(163)  评论(0编辑  收藏  举报
浏览器标题切换
浏览器标题切换end