git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

栏目: 编程工具 · 发布时间: 5年前

内容简介:错误提示:refusing to merge unrelated historiesThe local repository is out of date

git 本地仓库与远程仓库的强制合并

错误提示:

refusing to merge unrelated histories

The local repository is out of date

过程是这样的

今天在本地新建了一个 git 仓库,并往里添加了一些文件,也在本地提交了几次。

这时候再去 github 上新建了个仓库,然后把 github仓库添加到本地的仓库中。

git remote add rime git@github.com:KyleBing/rime-wubi86-jidan.git

可以看到已经添加了远程仓库:

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

pull 远程仓库的内容:

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

然后执行上传到 github 的时候出现下面错误:

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

错误原因

其实本地建的那个仓库和远程 github 仓库是两个独立的仓库,互不相关。

如果在建完 github 后再 git clone 到本地就不会出现该问题了。

解决办法

git pull 有个 --allow-unrelated-histories 参数,是为了合并两个不相关的仓库的历史,这个可以通过 git pull --h 查看帮助。

因为我们这两个仓库并没有冲突,可以直接合并:

git pull rime master --allow-unrelated-histories

这时候出现填写合并信息的窗口

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

填写保存后,结果显示,合并成功。

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

后续提交

# 提交更新到 github
kyle-mbp:Rime Kyle$ git push rime master

# 结果
Counting objects: 38, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (38/38), done.
Writing objects: 100% (38/38), 1.85 MiB | 305.00 KiB/s, done.
Total 38 (delta 20), reused 0 (delta 0)
remote: Resolving deltas: 100% (20/20), done.
To github.com:KyleBing/rime-wubi86-jidan.git
   27c22af..bf39b8c  master -> master

查看历史记录是这样的,可以看到本地 master 和远程 master 已经合并在一起了:

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

git 本地仓库与远程仓库的强制合并 refusing to merge unrelated histories

再看一下远程仓库的提交记录,已经能看到本地的提交记录了。

结决


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Hibernate

Hibernate

James Elliott / O'Reilly Media, Inc. / 2004-05-10 / USD 24.95

Do you enjoy writing software, except for the database code? Hibernate:A Developer's Notebook is for you. Database experts may enjoy fiddling with SQL, but you don't have to--the rest of the appl......一起来看看 《Hibernate》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具