本文介绍了为什么“git push helloworld + master:master”而不仅仅是“git push helloworld”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $ git push helloworld $ b $(git push helloworld $ b $) b  

但是我回过头来看看:

 [email protected]:helloworld.git 
! [被拒绝] HEAD - > master(非快速转发)错误:
未能将一些文件推送到'[email protected]:helloworld
git'

所以我发现。




注意:正如Junio C. Hamano提到的:






,可能的行动方案是:



  $ git fetch origin 
$ git log master..origin / master



其他解决方案(这是你所做的):

  $ git push origin + branchname 





  $ git push origin :branchname 
$ git push origin + branchname




I tried to push my (first ever!) git repo like this initially:

$ git push helloworld

But I got this back:

To [email protected]:helloworld.git
 ! [rejected]        HEAD -> master (non-fast forward) error:
 failed to push some refs to '[email protected]:helloworld
git'

So I found another StackOverflow question about "amended commits" and tried a suggestion from there without really knowing whether it would help me:

KaiserSosa@SMICHAELS /c/test/helloworld (master)
$ git push helloworld +master:master

It worked!

But I don't know why it fixed my problem :(

Could someone explain why this works but "git push helloworld" doesn't?

解决方案

It appears you have rewritten your history (SHA-1 associated with your commit) in your master branch.

That means, you can no longer push in a fast-forward mode.

the +master forces the push to take place:
By having the optional leading +, you can tell git to update the <dst> ref even when the update is not a fast forward.

Note: this could be bad if anyone else has already cloned your repository, since they will no longer be able to just pull your master branch without having some conflict.
See also this SO answer for more.


Note: as mentioned by Junio C. Hamano:


As mentioned in the Git FAQ, a possible course of action is:

 $ git fetch origin
 $ git log master..origin/master

Other solution (which is what you did):

$ git push origin +branchname
$ git push origin :branchname
$ git push origin +branchname

这篇关于为什么“git push helloworld + master:master”而不仅仅是“git push helloworld”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 09:48