博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
git pull报错:Auto Merge Failed的处理
阅读量:7115 次
发布时间:2019-06-28

本文共 1461 字,大约阅读时间需要 4 分钟。

hot3.png

1.出错场景:

    协同开发时,我们从远程上pull下代码的时候,出现以下提示信息:

    Auto Merge Failed; Fix Conflicts and Then Commit the Result.

    2.原因分析:

    利用git status,输出如下:

    root@hyk-virt:/# git 

    # On branch master

    # Your branch and 'origin/' have diverged,

    # and have 2 and 2 different commits each, respectively.

    #

    # Unmerged paths:

    #  (use "git add/rm ..." as appropriate to  resolution)

    #

    #   both modified:     /sources.list

    #

    # Changes not staged for commit:

    #  (use "git add ..." to update what will be committed)

    #  (use "git checkout -- ..." to discard changes in working directory)

    #

    #   modified:  cups/subscriptions.conf

    #   modified:  cups/subscriptions.conf.O

    #   modified:  mtab

    #   modified:  update-manager/release-upgrades

    #

    no changes ed to commit (use "git add" and/or "git commit -a")

    从git 的结果可以发现:其中sources.list这个文件存在合并冲突

    而进一步分析git pull的原理,实际上git pull是分了两步走的,(1)从远程pull下origin/master分支(2)将远程的origin/master分支与本地master分支进行合并

    以上的错误,是出在了第二步骤

    3.解决方法

    方法一:如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fh取得远程分支):

    $:git reset --hard origin/

    或者$:git reset --hard ORIG_HEAD

    解释:

    git-reset - Reset current HEAD to the specified state

    --hard

    Resets the index and working tree. Any changes to tracked files

    in the working tree since are discarded.

    方法二:我们不能丢弃本地修改,因为其中的某些内容的确是我们需要的,此时需要对unmerged的文件进行手动修改,删掉其中冲突的部分,然后运行如下命令

    $:git  filename

    $:git commit -m "message"

    方法三:如果我们觉得合并以后的文件内容比价混乱,想要废弃这次合并,回到合并之前的状态,那么可以运行如下命令:

    $:git reset --hard HEAD

转载于:https://my.oschina.net/u/914897/blog/464479

你可能感兴趣的文章
ElasticSearch 查询
查看>>
Zabbix通过JMX监控tomcat
查看>>
第七天 date
查看>>
zabbix_proxy部署
查看>>
文件属性设置常量
查看>>
ie6下png透明
查看>>
linux里边的显示结果有乱码(输入LANG=en无效)
查看>>
Citrix XenDesktop发布Centos 7.2桌面(三)--基本配置Centos7.2
查看>>
移动开发必备!15款jQuery Mobile插件
查看>>
es6从零学习(三):Class的基本用法
查看>>
二十一、当锚点遇到fixed(margin和padding)
查看>>
SpringMVC向前台返回JSON
查看>>
java内存管理浅析
查看>>
oracle trigger
查看>>
fio 使用总结
查看>>
service docker start 报错 :Failed to start docker.se
查看>>
谈成长,谈创新——QClub成都0615活动纪要
查看>>
Hadoop WritableComparable接口
查看>>
第 九 天 : 复 习 中 ( 二 )
查看>>
开机自动开启vmware
查看>>