GIT 在拉取其他分支后无法推送

3

我一开始在 admin 分支上工作,但是我需要在 develop 分支上完成一些事情,所以选择了 git pull origin develop

几天后,我仍然在 admin 分支上工作,但是加入了那些 develop 的内容。我想要推送到 admin 分支,这样一切都会变得正常。

但是我遇到了这个错误:

! [rejected] admin -> admin (non-fast-forward) error: failed to push some refs to 'git@git.mygit.com:mygit/mygit.git' consejo: Updates were rejected because the tip of your current branch is behind consejo: its remote counterpart. Integrate the remote changes (e.g. consejo: 'git pull ...') before pushing again. consejo: See the 'Note about fast-forwards' in 'git push --help' for details.

如果我尝试执行 git pull,我会再次从 develop 获取内容,并且会破坏我已经做好的一切(我正在使用 rebase),即使我执行 git pull origin admin

我是唯一在 admin 分支上工作的人,而 develop 分支上只有一个人并没有触及 admin 分支。

git branch -vv

* admin   238eab7 [origin/admin: ahead 37, behind 9] Entidades remodeladas. Mapeo de entidades separadas a YAML para mejor organización Limpieza de varias cosas que sobraban (bundles y demás) Separadas las configuraciones por tipo. Separados los servicios por bundle y tipo siguiendo las recomendaciones de Symfony2
  develop 7cc5c84 [origin/develop: behind 22] Eurotax funcinoando. Quitado Memcached en el entorno de DEV para DQL y metido en PROD

我不知道你的意思,也不知道该如何寻找它... 我在 Github 上非常懒惰,一直只用 rebase 进行 push/pull... :( - Robert W. Hunter
完成。第一行是我最后一次提交,我想将其推送到管理员。第二行似乎是我几周前在develop分支上提交的(当我在使用它之前移动到管理员以便在该分支上工作)。 - Robert W. Hunter
好的,请前往您的管理分支,并从远程拉取所有已更改的新内容。 - ckruczek
我现在在admin分支。当我输入git branch时,它会显示这个信息。如果我执行git pull命令,我会从develop分支获取内容,这就是问题所在... admin分支没有变化,最后一次更改是5天前由我进行的,在那之前我已经在admin分支上执行了git pull origin develop命令以从该分支获取内容。 - Robert W. Hunter
让我们在聊天中继续这个讨论 - ckruczek
显示剩余2条评论
1个回答

0
如果您使用rebase选项进行了pull操作,则会将管理员更改放在开发更改的顶部(带有新提交)。因此,管理员分支上的提交不再存在于您的本地分支中,而是被新的提交所替换。如果您确定您的更改是正确的,则必须使用--force选项进行推送。例如:
git push --force origin admin
当您使用--rebase选项进行pull操作时,您必须使用--force选项来替换远程存储库中的内容。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接