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,输出如下:

[email protected]:/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

原文地址:https://www.cnblogs.com/init-007/p/11560046.html

时间: 2024-08-29 23:19:21

git报错:Auto Merge Failed; Fix Conflicts and Then Commit的相关文章

git报错failed to push some refs to &#39;[email&#160;protected]:Markprint/github.git&#39;

 这个不知名小错误用了我两天的空余时间mmp   就是这里报的错 输入 git push origin master -f 解释为: 远程分支上存在本地分支中不存在的提交,往往是多人协作开发过程中遇到的问题,可以先fetch再merge,也就是pull,把远程分支上的提交合并到本地分支之后再push.如果你确定远程分支上那些提交都不需要了,那么直接git push origin master -f,强行让本地分支覆盖远程分支 终于有了,以后还需要具体研究一下 虽然用的github,但是要推广一下

git:Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).

Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists). 解决办法一:保留本地的更改,中止合并->重新合并->重新拉取 $:git merge --abort $:git reset --merge $:git pull 解决办法二:舍弃本地代码,远端版本覆盖本地版本(慎重) $:git fetch --all $:git reset --hard origin/ma

eclipse git 报错:the current branch is not configured for pull No value for key branch.xxx.merge found

eclipse git 报错:the current branch is not configured for pull No value for key branch.xxx.merge found in configuration 如图: 这是因为 在用gui创建分支的时候 config文件没有创建branch 在config文件加上 [branch "xxx"] remote = origin merge = refs/heads/xxx 即可 eclipse git 报错:th

解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists).

Git fetch和git pull的区别, 解决Git报错:error: You have not concluded your merge (MERGE_HEAD exists). 2017年02月22日 20:38:28 阅读数:19178 Git fetch和git pull的区别: 都可以从远程获取最新版本到本地 1.Git fetch:只是从远程获取最新版本到本地,不会merge(合并) $:git fetch origin master //从远程的origin的master主分支

git报错:&#39;fatal:remote origin already exists&#39;怎么处理?附上git常用操作以及说明。

git添加远程库的时候有可能出现如下的错误, 怎么解决? 只要两步: 1.先删除 $ git remote rm origin 2.再次执行添加就可以了. ----------------------------------------------git常用操作------------------------------------------------ 说明,以下整理来自廖雪峰大神的<git教程>. 各位童鞋要下载git但是网速不给力的,可以从这里下载:https://pan.baidu.

git报错:&#39;fatal:remote origin already exists

git报错:'fatal:remote origin already exists'怎么处理?附上git常用操作以及说明. git添加远程库的时候有可能出现如下的错误, 怎么解决? 只要两步: 1.先删除 1 $ git remote rm origin 2.再次执行添加就可以了. ----------------------------------------------git常用操作------------------------------------------------ 说明,以下整

关于spring-data-mongodb用户名密码登录报错问题:Failed to authenticate to database

一.问题 1.spring-data-mongodb用户名密码登录报错问题:Failed to authenticate to database  org.springframework.data.mongodb.CannotGetMongoDbConnectionException: Failed to authenticate to database [ashop], username = [ashop], password = [g***********4] org.springframe

iOS 报错: linker command failed with exit code 1 (use -v to see invocation) 原因

在iOS开发中,很多人会遇到这样的报错 linker command failed with exit code 1 (use -v to see invocation) 可能的原因如下: 1.引用出错,把***.h弄成了.m,检查一下你的所有引用: 2.再就是你引用第三方的库,你添加文件是系统没有所第三方库的.m文件参入的编译中去,你向项目添加文件得注意了; 3.找到Build settings->Linking->Other Linker Flags,将此属性修改成-all_load或-O

解决更新Xcode以后使用Git报错的问题

更新Xcode以后使用Git报错: [email protected] SecondApp$ git pull Agreeing to the Xcode/iOS license requires admin privileges, please re-run as root via sudo. 解决办法: 第一步: 输入下面的命令 bixiaopeng@bixiaopengtekiMacBook-Pro SecondApp$ sudo xcodebuild -license Password: