git pull origin master --allow-unrelated-histories
解决方案(正确方法附后文)
1、先创建一个远程仓库,比如在GitHub上 https://gitee.com/flist/Log4qt
2、本地添加远程仓库:
$ git remote add origin git@gitee.com:flist/Log4qt.git
$ git remote add origin git@gitee.com:flist/Log4qt.git
查看远程仓库:
Flist_liu@Computer-Liu MINGW64 /d/QtProject/Log4qtLearn (master)
$ git remote -v
origin git@gitee.com:flist/Log4qt.git (fetch)
origin git@gitee.com:flist/Log4qt.git (push)
3、从远程合并时会报错
$ git pull origin master
From gitee.com:flist/Log4qt
* branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories
4、加上参数: --allow-unrelated-histories
$ git pull origin master --allow-unrelated-histories
From gitee.com:flist/Log4qt
* branch master -> FETCH_HEAD
Merge made by the 'recursive' strategy.
README.md | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 README.md
5、拉取完成,推送
$ git push origin master
Counting objects: 13, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 2.58 KiB | 528.00 KiB/s, done.
Total 13 (delta 1), reused 0 (delta 0)
remote: Powered by Gitee.com
To gitee.com:flist/Log4qt.git
87dfdb2..21fe8fb master -> master
补充方法
将已有项目推送到远程新建仓库时操作如下:
cd existing_git_repo
git remote add origin git@gitee.com:flist/xxx(项目名称).git
git push -u origin master
结果:
$ git push -u origin master
Counting objects: 37, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (33/33), done.
Writing objects: 100% (37/37), 12.94 KiB | 2.16 MiB/s, done.
Total 37 (delta 12), reused 0 (delta 0)
remote: Powered by Gitee.com
To gitee.com:flist/QSSDemo.git
* [new branch] master -> master
Branch 'master' set up to track remote branch 'master' from 'origin'.
原文链接:https://blog.csdn.net/baidu_33850454/article/details/80866618
网友评论