git报错:Auto Merge Failed; Fix Conflicts and Then Commit
本文来源:http://blog.csdn.net/trochiluses/article/details/10100719
1.出错场景:
协同开发时,我们从远程服务器上pull下代码的时候,出现以下提示信息:
Auto Merge Failed; Fix Conflicts and Then Commit the Result.
2.原因分析:
利用git status,输出如下:
root@hyk-virt:/etc# git status
# On branch master
# Your branch and 'origin/master' have diverged,
# and have 2 and 2 different commits each, respectively.
#
# Unmerged paths:
# (use "git add/rm <file>..." as appropriate to mark resolution)
#
# both modified: apt/sources.list
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: cups/subscriptions.conf
# modified: cups/subscriptions.conf.O
# modified: mtab
# modified: update-manager/release-upgrades
#
no changes added to commit (use "git add" and/or "git commit -a")
从git status的结果可以发现:其中sources.list这个文件存在合并冲突
而进一步分析git pull的原理,实际上git pull是分了两步走的,(1)从远程pull下origin/master分支(2)将远程的origin/master分支与本地master分支进行合并
以上的错误,是出在了第二步骤
3.解决方法
方法一:如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行git fetch取得远程分支):
$:git reset --hard origin/master
或者$: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 <commit> are discarded.
方法二:我们不能丢弃本地修改,因为其中的某些内容的确是我们需要的,此时需要对unmerged的文件进行手动修改,删掉其中冲突的部分,然后运行如下命令
$:git add filename
$:git commit -m "message"
方法三:如果我们觉得合并以后的文件内容比价混乱,想要废弃这次合并,回到合并之前的状态,那么可以运行如下命令:
$:git reset --hard HEAD
相关文章
- Git rename from index.lock to index failed
- Command (Start this RegionServer (64250)) has failed CDH hbase 节点重启失败报错
- react-native 异常处理 Execution failed for task ':app:mergeDebugResources'.
- Failed to connect socket to '/var/run/libvirt/libvirt-sock': No such file or directory
- git clone时出现"fatal: unable to access 'https://myrepo.git/': server certificate verification failed. CAfile: /my-certificate CRLfile: none"时如何处理?
- git clone时报错“Failed to connect to 127.0.0.1 port 2453: Connection refused”如何处理?
- git遇到error: RPC failed; curl 18 transfer closed with outstanding read data remaining fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed failed怎么办?
- nginx: [emerg] bind() to 0.0.0.0:443 failed(98:Address already in use)解决方法
- 编译时弹出“configure: error: libtool configure failed
- git clone error: RPC failed; curl 18 transfer closed with outstanding read data remaining
- Python Manim 问题解决大全之 如何解决 latex failed but did not produce a log file
- vscode Git:failed to execute git
- SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder"
- Jenkins+GitHub报错hudson.plugins.git.GitException: Failed to fetch from GitHub 443
- 使用Anaconda安装Tensorflow在导入模块时会出现ImportError: DLL load failed: 找不到指定的模块的问题
- 小米手机 DELETE_FAILED_INTERNAL_ERROR Error while Installing APKs
- git:early EOF the remote end hung up unexpectedly index-pack failed RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 10054
- git clone失败:fatal: unable to access 'https://github.com/NVIDIA/apex/': gnutls_handshake() failed: The TLS connection was non-properly terminated.
- Flume接收消息出现FAILED:Event exceeds the maximum length(512 chars, including newline)