GIT错误 - 无法将远程仓库和本地仓库合并

2018-12-08  本文已影响0人  linklinco

1、错误反馈如下

木羽@yollose MINGW64 ~/Desktop/tmp (master)
$ git push origin master
To github.com:yollose/new.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:yollose/new.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

2、产生原因:

git不允许合并两个没有公共基础的仓库,本地仓库和远程仓库出现了冲突,一般在github中创建远程仓库时添加README.MD会出现。

3、解决方案:

$ git pull origin master --allow-unrelated-histories

添加--allow-unrelated-histories,让git忽略两仓库的历史,强行合并

合并后代码:

木羽@yollose MINGW64 ~/Desktop/tmp (master)
$ git pull origin master --allow-unrelated-histories
From github.com:yollose/new
 * branch            master     -> FETCH_HEAD
Auto-merging 1.txt
Merge made by the 'recursive' strategy.
 .gitignore | 330 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1.txt      |   2 +
 2 files changed, 332 insertions(+)
 create mode 100644 .gitignore

4、防范措施

可以考虑在创建github远程仓库时,不选择添加README.MD。或者直接使用git clone来使用远程仓库

5、参考链接

其他解决方案:github上的版本和本地版本冲突的解决方法

上一篇 下一篇

猜你喜欢

热点阅读