美文网首页
GIT错误 - 无法将远程仓库和本地仓库合并

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

作者: linklinco | 来源:发表于2018-12-08 22:05 被阅读0次

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上的版本和本地版本冲突的解决方法

相关文章

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

    1、错误反馈如下 2、产生原因: git不允许合并两个没有公共基础的仓库,本地仓库和远程仓库出现了冲突,一般在gi...

  • gitDemo远程操作演练

    gitDemo远程操作演练 1.将本地仓库与远程仓库进行合并 git@github.com:longxianwen...

  • Git GUI (可视化git)

    1 在git仓库右键选择Git GUI here 2下拉远程仓库 3合并到本地仓库 以上是远程仓库与本地仓库保持一...

  • Git~将本地项目推送到远程仓库

    Git~将本地项目推送到远程仓库 0、前言 如果应经有远程仓库和本地仓库,那么本地仓库和远程仓库实际上是独立的两个...

  • Git基本操作和错误

    创建SSH Key 本地创建仓库操作 创建本地仓库 将文件添加进Git 提交 Git远程仓库操作 查看远程仓库 添...

  • Git 上传文件命令

    git添加到本地仓库 git提交到本地仓库 git推送到远程仓库 git合并分支 当前配置链接命令 把当前地址设置...

  • git本地仓库的理解

    git本地仓库的理解 学习Git时总听人说git分为本地仓库和远程仓库,但是远程仓库还好理解,本地仓库在哪呢,根本...

  • 将本地git仓库关联至远程git仓库 2019-11-20(未经

    如何将本地git仓库关联至远程git仓库 以本地git仓库关联GitHub仓库为例: 在github上新建仓库(注...

  • 版本库交互

    版本库间的交互分为本地仓库推送到远程仓库和远程仓库拉取到本地仓库。 将工作区中的代码合并到本地仓库的操作叫做提交,...

  • git命令行操作

    本地仓库和远程仓库的中间缓存将git暂存区的文件推送到远程仓库放入暂存区git add .git commit -...

网友评论

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

      本文链接:https://www.haomeiwen.com/subject/anuchqtx.html