git提交冲突:To https://gitee.com/men_zi_qi/practical-training.git ! [rejected] dev -> dev (fetch first)

git提交后发生冲突:To https://gitee.com.git
! [rejected] dev -> dev (fetch first)
error: failed to push some refs to ‘https://gitee.com/men_zi_qi/practical-training.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.
在这里插入图片描述
产生原因:同一个项目,不同员工操作相同位置提交后发生冲突。

解决方法:

按照它的提示:

  1. git pull origin dev
    在这里插入图片描述
    它尝试自动合并后失败了,说需要去手动合并。

  2. 去代码中看,会发现多出来一段神奇的代码
    在这里插入图片描述

以上代码是 员工A和员工B同时提交造成的

  1. 以下所框起来的代码就是产生冲突的代码
    HEAD自己的代码;=======远程的代码
    List item

  2. 手动删除 并合并 解决冲突
    List item

  3. 命令行再次提交:搞定

git add .
git commit -m '解决冲突了啊哈'
git push origin dev

在这里插入图片描述

  1. 正常流程需另一位提交员工:git pull origin dev 完美
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Menqq/article/details/114034902