Fatal: Not possible to fast-forward, aborting

git是一个很好用的版本管理工具,然而,有时候一些冲突还是让人很郁闷的。
遇到过两次merge报错,是在不同的情形下出现的。

  • 本地分支各自commit之后,merge
  • 本地master分支 pull 远程master分支

下面记录以下两种情况的处理。

情形1:


我在本地仓库的两条分支devmaster同时开发,各自经过2个提交之后,merge报错:

fatal: Not possible to fast-forward, aborting.

如果git环境是中文的,那么这个错误信息就是这样的:

fatal:无法快进,终止。

问题的原因:

两个分之同时改了同样的地方,造成冲突。
按理,这种冲突也可以直接运行merge,然后手动解决这些冲突,再commit就行了。
然而,这次不行。

那就使用另一种合并分支的办法:rebase,我的目的是将dev合并到master,然后删除dev

git checkout master
git rebase dev

这时候报以下错误:

First, rewinding head to replay your work on top of it...
Applying: text:I am on master
Using index info to reconstruct a base tree...
M   a.txt
Falling back to patching base and 3-way merge...
Auto-merging a.txt
CONFLICT (content): Merge conflict in a.txt
error: Failed to merge in the changes.
Patch failed at 0001 text:I am on master
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

这时候需要手动去修改冲突的地方:

<<<<<<< HEAD
I am on dev

I am on my mark.
=======
I am on master
>>>>>>> text:I am on master

然后,根据上面报错的提示信息,continue

When you have resolved this problem, run "git rebase --continue".
git rebase --continue 

a.txt: needs merge
You must edit all merge conflicts and then
mark them as resolved using git add

根据提示,add之后,再看下状态:

git add .
git status

rebase in progress; onto 6114f0b
You are currently rebasing branch 'master' on '6114f0b'.
  (all conflicts fixed: run "git rebase --continue")

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    modified:   a.txt

已经提示冲突都已经解决,可以继续了:

git rebase --continue

Applying: text:I am on master
Applying: commit 2nd
Using index info to reconstruct a base tree...
M   a.txt
Falling back to patching base and 3-way merge...
Auto-merging a.txt

这时候dev分支已经完全合并到了master分支上了:

git status

On branch master
nothing to commit, working tree clean

情形2:


其实处理方式跟情形1是一样的,只是稍有不同。

git pull origin master

From https://gitee.com/leonxtp/xxxxx
 * branch            master     -> FETCH_HEAD
fatal: Not possible to fast-forward, aborting.

这时候直接应用rebase解决:

git pull origin master --rebase

First, rewinding head to replay your work on top of it...
Applying: xxxxxx
Using index info to reconstruct a base tree...
M       gradle.properties
Falling back to patching base and 3-way merge...
Auto-merging path/of/file...
Auto-merging path/of/file...
Applying: yyyyyyy
...

关于mergerebase的区别,可以参考:这篇文章
个人总结起来就是:

  • merge不影响原来的commit,并会新增一个合并的commit
  • rebase是将目标分支插入到两个分支的共同祖先与当前分支的最后面(不是最新)之间,并且修改当前分支原来的commit,但不会增加新的commit

问题解决参考SOF

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Git是目前最流行的版本管理系统,也是最先进的分布式版本控制系统(distributed version cont...
    pro648阅读 5,921评论 1 17
  • 本文为 Git教程的学习笔记,教程源自廖雪峰的博客。这是一个由浅入深,学完后能立刻上手的Git教程。另,附上另一本...
    七弦桐语阅读 6,428评论 5 47
  • (二十四)二雅的骤变 光阴如箭,俱乐部开张至今一晃都快要两年了。当年十七岁的张二雅如今己是十九岁了。...
    能安大鹏阅读 559评论 0 0
  • 1 有一个明明看上去高大威猛,笑起来却像小孩子一样单纯无害的人,无论输了赢了都爱哭爱闹,还被大家叫做小哭包的人。 ...
    花田夜语阅读 689评论 3 17

友情链接更多精彩内容