首页 > 其他分享 >Git必知必会基础(12):远程冲突(conflicts)解决--merge

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

时间:2024-01-27 20:07:38浏览次数:30  
标签:12 hint 必知 merge git master qzcsbj push 分支

 

演示场景

虽然每次合并代码前会先把分支更新到最新,但是在你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.

 

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

 

数据准备

重新克隆

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库

 

日志

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

 

远程分支qzcsbj.txt内容

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_03

 

commit id

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_04

 

其他人提交

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

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_05

 

新的commit id

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

 

本地提交

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

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_07

 

先提交到本地仓库

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_08

 

日志

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_09

 

推送到远程仓库,报错

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_10

 

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不是最新的

 

解决冲突

将远程仓库的master分支下载到本地当前branch中

git fetch origin master

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_11

 

可以查看本地分支和fetch的分支差异:git diff master FETCH_HEAD,我们这里只有qzcsbj.txt的内容有差异

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

 

git diff master origin/master

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_13

 

进行合并:git merge origin/master

或者:git merge fetch_head

提示做了自动合并,但是自动合并失败了;另外,下面master -> origin的颜色变了

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

 

查看文件内容

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_15

 

合并内容为:

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_16

 

再次推送

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_17

 

To gitee.com:qzcsbj/pytest_apiautotest.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'gitee.com:qzcsbj/pytest_apiautotest.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

 

大概意思是:当前分支落后远程分支

问题原因是:刚刚我们已经和远程分支合并了,但是没提交到本地仓库,所以执行下面操作:

git status

git add .

git commit -m "xxx"

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

 

git push

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_19

 

push成功后,远程分支内容

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_20

 

新的commit id

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_21

 

日志:下面c545426是模拟别人提交的id

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_22

 

查看分支合并图

git log --graph

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

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程仓库_24

 

git log --graph --oneline

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_25

Git必知必会基础(12):远程冲突(conflicts)解决--merge_远程分支_26

 

 

 

__EOF__


本文作者:持之以恒(韧)
关于博主:擅长性能、全链路、自动化、企业级自动化持续集成(DevTestOps)、测开等


标签:12,hint,必知,merge,git,master,qzcsbj,push,分支
From: https://blog.51cto.com/qzcsbj/9444203

相关文章

  • Git必知必会基础(16):git clone、git pull、git fetch、git push的区别
     gitclone没有本地仓库,将远端的整个项目下载到本地 gitpull本地已经有项目但不是最新(比如你的同事往远处仓库提交了代码),从远程获取最新版本并merge到本地,也就是将远程指定分支拉取到本地指定分支上命令格式:gitpull[远程仓库名][远程分支名]:[本地分支名]本地分支是当前分......
  • 牛客练习赛121补题
    C.思路由于水滴会影响一个区间里的水滴,所以只需要为何区间[l,r]即可ac代码#include<bits/stdc++.h>usingnamespacestd;usingi64=longlong;consti64inf=1e18;typedefpair<int,int>pii;constintmod=1e9+7;constintN=2e5+10;inta[N];intn......
  • (坚持每天写算法)算法复习与学习part1基础算法part1-12——双指针算法
    双指针是一种思路,很多题都可能用得到,这里我就只选取Acwing网站的三道题(事实上我最近就是在这里刷题,leetcode反而不怎么去了,刷完这个网站的我就会去leetcode刷了)双指针一般来讲会在数组有序的情况下应用,但是如果是无序的也是有可能的,两个指针会遍历整个数组(如果条件允许的......
  • STM32CubeMX教程26 FatFs 文件系统 - W25Q128读写
    1、准备材料正点原子stm32f407探索者开发板V2.4STM32CubeMX软件(Version6.10.0)keilµVision5IDE(MDK-Arm)ST-LINK/V2驱动野火DAP仿真器XCOMV2.6串口助手2、实验目标使用STM32CubeMX软件配置STM32F407开发板使用FatFs中间件通过SPI通信协议对W25Q128芯片进行读写等操作3......
  • SQL Server 2012 版本后的自带分页语法
    SQLServer2012与之前版本相比,增加了好多实用性的功能,在之前,数据表中的记录较多,需要分页时,算法比较麻烦,2012版本之后,增加了优雅分页语法,可通过简单的语法实现分页:Select*FromTb_tableOrderBy<排序列>OffSet<起始位置>ROWSFetchNext<返回的行数>RowsOnly说明:1、<......
  • 牛客练习赛121
    牛客练习赛121出题人题解|牛客练习赛121题解小念吹气球解题思路:字符长度加字符种类数。代码:#include<bits/stdc++.h>usingnamespacestd;usingll=longlong;usingpii=pair<ll,ll>;#definefifirst#definesesecondusingi128=__int128_t;voidso......
  • Java学习日记 Day12 心累~
    SpringMVC:主要学了SpringMVC架构下请求与响应的各种方式,在响应中要知道请求转发和重定向的区别。算法:合并二叉树:判断当前节点两棵树的数值关系,然后递归判断左右子树的关系。二叉搜索树中的搜索:根据二叉搜索树的特点,递归查找左右子树,当值相等就返回。验证二叉搜索树:为自己的左......
  • 2023.12.9 总结
    T1题意:一枚棋子每一步只能走到与它原位置不同行与不同列的位置,现在将其放在一个\(R\)行\(C\)列的棋盘中,此棋子走\(N\)步,经过的点构成一个排列,问有多少种不同排列?\((R,C,N\le200)\)初步思路此题是\(DP\)。设\(f_{i,j,u}\)为走了\(i\)步,在\(j,u\)位置的走法,每一......
  • Codeforces Round 912 (Div
    AHalloumiBoxes题目大意给定一个数组A,我们可以对数组惊醒多次操作,操作如下:我们可以将数组中的某一段倒置,但是长度不能超过K,例如:反转子数组意味着选择两个索引i和j(其中1<=i<=j<=n)并将数组\[a_1,a_2,…,a_n\]改为\[a_1,a_2,…,a_{i−1},a_{j},a_{j−1},…......
  • 洛谷题解-P2712 摄像头
    https://www.luogu.com.cn/problem/P2712可以看出是拓扑排序,因为是有前后关系的,但是坑点在于点并不连续,值得记录一下(刚开始70分,后来才AC)注意坑点:拓扑排序,遍历的点不连续 #include<bits/stdc++.h>usingnamespacestd;constintN=1e5+5;intn,x,m,y,d[N],cnt=0,v......