功能分支重新设置后,Git推送被拒绝

两盒软妹~` 提交于 2020-08-12 03:40:00

问题:

OK, I thought this was a simple git scenario, what am I missing? 好的,我以为这是一个简单的git场景,我缺少什么?

I have a master branch and a feature branch. 我有一个master分支和一个feature分支。 I do some work on master , some on feature , and then some more on master . 我在master上做一些工作,在feature上做一些,然后再在master上做更多的工作。 I end up with something like this (lexicographic order implies the order of commits): 我最终得到这样的东西(字典顺序暗示着提交的顺序):

A--B--C------F--G  (master)
       \    
        D--E  (feature)

I have no problem to git push origin master to keep the remote master updated, nor with git push origin feature (when on feature ) to maintain a remote backup for my feature work. 我可以使用git push origin master来保持远程master更新,也没有问题,可以使用git push origin feature (在feature )来为我的feature工作维护远程备份。 Up until now, we're good. 到目前为止,我们还不错。

But now I want to rebase feature on top of the F--G commits on master, so I git checkout feature and git rebase master . 但现在我要重订feature在上面F--G上主提交,所以我git checkout featuregit rebase master Still good. 还好。 Now we have: 现在我们有:

A--B--C------F--G  (master)
                 \
                  D'--E'  (feature)

Problem: the moment I want to backup the new rebased feature branched with git push origin feature , the push is rejected since the tree has changed due to the rebasing. 问题:当我要备份以git push origin feature feature分支的新的基于重载的feature ,由于树由于重新定基而发生了更改,因此该推送被拒绝了。 This can only be solved with git push --force origin feature . 这只能通过git push --force origin feature解决。

I hate using --force without being sure I need it. 我讨厌使用--force不确定自己是否需要它。 So, do I need it? 所以,我需要吗? Does the rebasing necessarily imply that the next push should be --force ful? 请问垫底一定意味着未来push应该是--force FUL?

This feature branch is not shared with any other devs, so I have no problem de facto with the force push, I'm not going to lose any data, the question is more conceptual. 此功能分支未与任何其他开发人员共享,因此对于强制推送我实际上没有问题,我也不会丢失任何数据,这个问题更具概念性。


解决方案:

参考一: https://stackoom.com/question/bVhB/功能分支重新设置后-Git推送被拒绝
参考二: https://oldbug.net/q/bVhB/Git-push-rejected-after-feature-branch-rebase
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!