简体   繁体   English

重置后将master分支推送到github存储库

[英]Pushing a master branch to github repository after reset

So basically for whatever reason after merging my master branch with another branch and pushing master branch to github repo my code was filled with <<<<<<< HEAD for whatever reason, even in places that I edited many commits ago so what I did was git reset --hard to the previous commit and that fixed the code now when I try to push my master branch to github repo I get 所以基本上无论出于什么原因,在将我的master分支与另一个分支合并并将master分支推送到github <<<<<<< HEAD ,无论出于什么原因,我的代码都充满了<<<<<<< HEAD ,即使在我之前编辑了很多commit的地方,我也做了是git reset --hard到上一次提交,现在我尝试将master分支推送到github repo时修复了代码

 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'my github repo'
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.

now doing git pull would just give me the code that's filled <<<<<<HEAD which I don't need. 现在执行git pull只会给我填充<<<<<<HEAD的代码<<<<<<HEAD So I looked for some solutions and the first few results suggested git push -f origin branch but when I do that I get 所以我寻找了一些解决方案,前几个结果建议使用git push -f origin branch但是当我这样做时,我得到了

error: src refspec branch does not match any.
error: failed to push some refs to my github repo

so what should I do now, lads? 那伙计们,我现在该怎么办?

git push github master
To git@github.com:Joey-project/project.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Joey-project/project.git'

is an often reoccuring error. 是经常发生的错误。

I've read that one of the solutions is to use a variation of the following commands: 我已经读过解决方案之一是使用以下命令的变体:

git fetch github; git merge github/master

May I suggest you to also look at Git non-fast-forward updates were rejected Merge the remote changes , it has a lot of extra information.. 我想建议您也看看Git非快进更新被拒绝合并远程更改 ,它有很多附加信息。

found it myself 我自己找到了

git push origin HEAD --force

does the trick. 绝招。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM