git报错:Pull is not possible because you have unmerged files解决方法

2022-06-18 16:49:43 浏览数 (2)

git报错:Pull is not possible because you have unmerged files解决方法

开发提交git pull报错

代码语言:txt复制
Your branch and 'origin/online' have diverged,
and have 12 and 1 different commit each, respectively.
  (use "git pull" to merge the remote branch into yours)
Auto-merging api/Tpl/Template_api/recharge_coin.html
CONFLICT (content): Merge conflict in api/Tpl/Template_api/recharge_coin.html
Automatic merge failed; fix conflicts and then commit the result.
error: you need to resolve your current index first
api/Tpl/Template_api/recharge_coin.html: needs merge
Build step 'Execute shell' marked build as failure
Finished: FAILURE

本地的push和merge会形成MERGE-HEAD(FETCH-HEAD), HEAD(PUSH-HEAD)这样的引用。HEAD代表本地最近成功push后形成的引用。MERGE-HEAD表示成功pull后形成的引用。可以通过MERGE-HEAD或者HEAD来实现类型与svn revet的效果。

git reset --hard FETCH_HEAD

//将本地的冲突文件冲掉,不仅需要reset到MERGE-HEAD或者HEAD,还需要--hard。没有后面的hard,不会冲掉本地工作区。只会冲掉stage区。

这个需谨慎,最好先备份,我搞过一次就是刚做的啥也没啦

修复操作

代码语言:txt复制
$ git status
# On branch online
# Your branch and 'origin/online' have diverged,
# and have 12 and 2 different commits each, respectively.
#   (use "git pull" to merge the remote branch into yours)
#
# You have unmerged paths.
#   (fix conflicts and run "git commit")
#
# Unmerged paths:
#   (use "git add <file>..." to mark resolution)
#
#       both modified:      api/Tpl/Template_api/recharge_coin.html
#
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#       deleted:    api/Conf/api/7477.ucconfig-sample.php
#       deleted:    api/Conf/config-sample.php
#       deleted:    api/Conf/dbconfig.inc-sample.php
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git reset --hard FETCH_HEAD
HEAD is now at 5d2bfb0 调试
$ git pull
Already up-to-date.
$ ll api/Tpl/Template_api/recharge_coin.html
-rw-rw-r-- 1 www www 8484 Dec 23 21:11 api/Tpl/Template_api/recharge_coin.html

$ git status
# On branch master
nothing to commit, working directory clean

0 人点赞