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
相关文章推荐
- git pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result.
- 芒果iOS开发之 CONFLICT (content): AutoMatic merge failed;fix conflicts and then commit the result.
- git 使用场景一,pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result.
- git pull报错:Auto Merge Failed; Fix Conflicts and Then Commit the Result.
- git常见问题之:commit your changes or stash them before you can merge
- 解决Anaconda下“The kernel has died, and the automatic restart has failed.” 的问题
- Git出现error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge.的问题解决(Git代码冲突)
- Git出现error: Your local changes to the following files would be overwritten by merge: ... Please, commit your changes or stash them before you can merge.的问题解决(Git代码冲突)
- git常见问题之git pull时Please specify which branch you want to merge with.
- git常见问题之git pull origin master时fatal: refusing to merge unrelated histories
- git---如何解决git pull之后报错:Please enter a commit to explain why this merge is necessary?(merge branch)
- git pull error:You are in the middle of a conflicted merge
- git pull出错fatal:Please make sure you have the correct access rights.and the repository exists.
- git commit遇到的问题:The file will have its original line ...(亲测可用)
- How to fix the problem of executing gitenv.csh file failed
- git pull 遇到本地有修改,不能merge的问题
- Git pull 报 error: Your local changes to the following files would be overwritten by merge: xxx.java
- git pull 时出现 error: Your local changes to the following files would be overwritten by merge的解决办法
- git push error: RPC failed; result=56, HTTP code = 0 ,the remote end hung up unexpectedly
- iOS常见问题之 Restore the connection to device and run “xxx” again, or if “xxx” is still ru