Git:压扁时的恶性循环...在变基后,提交从日志中消失

时间:2017-11-03 13:21:34

标签: git

我有几次提交壁球(但并非所有这些都需要被压扁!):

commit b1
commit b2
commit c1
commit c2
commit d1
commit m2

我输入git rebase -i HEAD~6

commit b1
s b2
s c1
s c2
s m2

最后,我希望提交所有压缩的提交!

但是当我试图将这些更改推送到我的开发分支(myBranch)时 ,我得到了以下众所周知的错误:

    ! [rejected]            myBranch -> myBranch (non-fast-forward)
error: failed to push some refs to 'git@....git'
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

根据需要,我正在输入git pull --rebase origin myBranch,然后我的提交从git log消失了,一切又回来了!

如何修复此问题并将压缩的提交推送到dev分支?这里有什么步骤?

谢谢!

1 个答案:

答案 0 :(得分:1)

一切都很好。来自git的那条消息具有误导性。相反,您需要将-f添加到push命令。

原因是git试图保护您免于因更换远程分支头而意外丢失历史记录(而不是快速推送)。所以你需要太强迫推动。如果您正在与其他人合作,您需要事先与他们沟通,但我会假设您在这里独自工作。

相关问题