为什么“git push helloworld + master:master”而不仅仅是“git push helloworld”? [英] Why "git push helloworld +master:master" instead of just "git push helloworld"?

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

问题描述

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

但是我回过头来看看:

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

所以我发现,并从那里尝试了一个建议,但并不知道它是否会帮助我:

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

它有效!

但我不知道为什么它解决了我的问题:( p>

有人可以解释为什么可以这样工作,但是 git push helloworld 没有?


看起来您已在您的主分支中重写了您的历史记录(与提交相关的SHA-1)。



这意味着,你不能再推入快进模式/ p>

+ master强制推送发生:

通过使用可选的前导+,可以告诉git更新< dst> ref即使更新不是快进。



注意:如果其他人已经克隆您的存储库,因为他们将不再能够在没有冲突的情况下拉动主分支。

另请参阅
SO answer for more




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


有两种独立的安全机制:


  • 发送端的安全性可以被 git push --force 和/或通过使用带有前缀' + ');


  • 接收端的安全性可以被您推入的存储库的配置变量 receive.denynonfastworwards 覆盖。


>

后者默认为不安全,但是如果在存储库中激活了安全性,则从发送方强制不会停用它。 IOW,两端都必须同意允许不安全的行为。







Git FAQ ,可能的行动方案是:


最可能的原因是您需要先从远程获取数据。通过首先获取并检查日志,您可以看到远程端发生了什么变化。例如,



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




会列出远端有你身边的所有变化如果你想要一个图形表示,使用 gitk --left-right 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 git-smichaels@free5.projectlocker.com:helloworld.git
 ! [rejected]        HEAD -> master (non-fast forward) error:
 failed to push some refs to 'git-smichaels@free5.projectlocker.com: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:

There are two independent safety mechanisms:

  • the sending end safety can be overridden by "git push --force" and/or by using a refspec prefixed with a '+');

  • the receiving end safety can be overridden by the config variable receive.denynonfastworwards of the repository you are pushing into.

The latter defaults to "unsafe", but if the safety is activated in the repository, forcing from the sending side will not deactivate it. IOW, both ends need to agree to allow the unsafe behavior.


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

The most likely reason for this is that you need to pull from the remote first. You can see what changes the remote side has by fetching first and then checking the log. For example,

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

will list all the changes the remote side has that your side doesn't.
If you want a graphical representation, use gitk --left-right master...origin/master.
The arrows to the left are changes you want to push, the arrows to the right are changes on the remote side.

Other solution (which is what you did):

$ git push origin +branchname

This will force the update. If you don't have permission, then sometimes this will work:

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

i.e., delete the branch remotely first (this is often permitted), then re-push the "new" (or perhaps rewound) branch.

Be warned that if you rewind branches, others might get into problem when pulling.
There is the chance that they will merge in the branch that they fetched with the new one that you've published, effectively keeping the changes that you are trying to get rid of.
However, it will only be their copies that have the bad revisions. For this reason, rewinding branches is considered mildly antisocial. Nonetheless, it is often appropriate.

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

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