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

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

内容简介:错误提示: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

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

结决


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

查看所有标签

猜你喜欢:

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

Purely Functional Data Structures

Purely Functional Data Structures

Chris Okasaki / Cambridge University Press / 1999-6-13 / USD 49.99

Most books on data structures assume an imperative language such as C or C++. However, data structures for these languages do not always translate well to functional languages such as Standard ML, Ha......一起来看看 《Purely Functional Data Structures》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具