当我运行"git pull origin master"时,出现拒绝合并错误 [英] get refuse to merge error when I run "git pull origin master"

查看:406
本文介绍了当我运行"git pull origin master"时,出现拒绝合并错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

按照多元视觉课程创建Visual Studio代码扩展.

following a pluralsight course to create a visual studio code extension.

但是在设置github存储库时出现错误. 当我运行"git pull origin master"时,出现错误拒绝合并无关的历史记录"

but getting an error when setting up the github repository. When I run "git pull origin master" I get error "refusing to merge unrelated histories"

这是我在运行代码并创建扩展名后运行的git命令:

here are the git commands I run after yo code runs and creates the extension:

git add .
git commit -m "Initial Commit"

在github上创建仓库

create the repo up on github

git remote add origin https://github.com/lae0901/static-site-hero.git
git push origin master
git pull origin master

github完全让我感到困惑.如何合并原点和母版?

github is totally confusing to me. How to merge origin and master?

谢谢

这是我正在执行的所有步骤: 在Windows中打开node.js命令提示符

here are all the steps I am running: open a node.js command prompt in windows

-运行您的代码以创建扩展名

-- run yo code to create the extension

yo code

?您要创建哪种扩展名?新扩展(JavaScript)
?您的扩展名是什么?静态网站英雄
?您的扩展程序的标识符是什么?静态网站英雄
?您对扩展程序的描述是什么?静态网站英雄
?您的发布商名称是什么(更多信息: https://code.visualstudio.com/docs/tools/vscecli#_publishing-extensions )? lae0
901
?初始化git仓库? (是/否)是

? What type of extension do you want to create? New Extension (JavaScript)
? What's the name of your extension? static site hero
? What's the identifier of your extension? static-site-hero
? What's the description of your extension? static site hero
? What's your publisher name (more info: https://code.visualstudio.com/docs/tools/vscecli#_publishing-extensions)? lae0
901
? Initialize a git repository? (Y/n) Y

-cd到扩展目录

cd static-site-hero

git status
git add .
git commit -m "Initial Commit"

登录github.com 创建一个新的存储库 将名称设置为扩展名.添加许可证-麻省理工学院 点击创建存储库" 点击下载下拉列表,找到存储库的网址

login to github.com create a new repository set name to name of the extension. add license - MIT click "create repository" click the download dropdown to find the url of the repo

git remote add origin https://github.com/lae0901/static-site-hero.git

-检查配置是否正确:

git remote --verbose

-这就是显示的内容

C:\ Users \ Steve \ static-site-hero> git remote --verbose
来源 https://github.com/lae0901/static-site-hero.git(获取)
来源 https://github.com/lae0901/static-site-hero.git(推)

C:\Users\Steve\static-site-hero>git remote --verbose
origin https://github.com/lae0901/static-site-hero.git (fetch)
origin https://github.com/lae0901/static-site-hero.git (push)

-首先是我git push origin master.但这失败了:

-- first I git push origin master. But that fails:

C:\Users\Steve\static-site-hero>git push origin master

https://github.com/lae0901/static-site-hero. git

! [拒绝]管理员->管理员(非快进) 错误:无法将某些引用推送到' https://github.com/lae0901/static -site-hero.git " 提示:更新被拒绝,因为当前分支的尖端在后面 提示:它的远程副本.集成远程更改(例如 提示:"git pull ..."),然后再次按下. 提示:有关详细信息,请参见"git push --help"中的关于快进的注意事项".

! [rejected] master -> master (non-fast-forward) error: failed to push some refs to 'https://github.com/lae0901/static-site-hero.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.

-然后git pull origin master也失败

C:\Users\Steve\static-site-hero> git pull origin master

警告:没有常见的提交 远程:计数对象:3,完成. 远程:压缩对象:100%(2/2),已完成. 远程:总计3(增量0),重用0(增量0),包重用0 打开包装箱:100%(3/3),已完成. 来自 https://github.com/lae0901/static-site-hero *分支主管-> FETCH_HEAD * [新分支]母版->来源/母版 致命的:拒绝合并无关的历史

warning: no common commits remote: Counting objects: 3, done. remote: Compressing objects: 100% (2/2), done. remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 Unpacking objects: 100% (3/3), done. From https://github.com/lae0901/static-site-hero * branch master -> FETCH_HEAD * [new branch] master -> origin/master fatal: refusing to merge unrelated histories

如何更正此错误?为什么拒绝合并无关的历史记录?

How to correct this error? Why refuse to merge unrelated histories?

推荐答案

之所以发生这种情况,是因为Github存储库具有您在创建许可证时所做的初始提交.该许可证提交不在您的本地分支中,因此GitHub认为您有两个不相关的项目,您不能推送或拉出.理想情况下,在将存储库推送到GitHub之前,不应该先从GitHub上的提交开始.虽然一切都没有丢失.

This is happening because the Github repository has an initial commit that you made when you created the license. That license commit is not in your local branch so GitHub thinks you have two unrelated projects and you can't push or pull. Ideally you wound not start with a commit on GitHub before you've pushed your repo to it. All is not lost though.

您可以通过以下方式从Github中提取提交,并告诉它忽略无关的历史记录:

You can pull the commit from Github and tell it to ignore unrelated histories with:

git pull origin master --allow-unrelated-histories

这将合并到您的本地分支机构的许可证中.然后,您应该可以推送到Github.

This will merge in the license to your local branch. Then you should be able to push to Github.

这篇关于当我运行"git pull origin master"时,出现拒绝合并错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆