您的位置:首页 > 大数据 > 人工智能

git常见问题之git pull时Automatic merge failed; fix conflicts and then commit the result.

2017-08-16 10:00 531 查看
Administrator@PC-20151117FT04 MINGW64 /e/AsWorkspace/AndroidStudy (master)
$ git pull origin master --allow-unrelated-histories
From github.com:nonfuxinyang/android-study
 * branch            master     -> FETCH_HEAD
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.


问题:Automatic merge failed; fix conflicts and then commit the result.
分析git pull的原理,实际上git pull是分了两步走的

(1)从远程pull下origin/master分支

(2)将远程的origin/master分支与本地master分支进行合并
以上的错误,是出在了第二步骤

解决方法

方法一:如果我们确定远程的分支正好是我们需要的,而本地的分支上的修改比较陈旧或者不正确,那么可以直接丢弃本地分支内容,运行如下命令(看需要决定是否需要运行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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐