压入本地提交后推送到远程分支失败

Neo*_*air 3 git version-control github rebase git-rebase

我对分支进行了三次提交,并将它们分别推送到远程。然后,我需要压缩提交,因此我使用了:

git reset --soft HEAD~3 && git commit
git push --force
Run Code Online (Sandbox Code Playgroud)

在第二行,我遇到一个致命错误:

The current branch [BRANCH-NAME] has no upstream branch.
To push the current branch and set the remote as upstream.
Run Code Online (Sandbox Code Playgroud)

我使用尝试了它的建议命令git push --set-upstream origin [BRANCH-NAME],但被告知当前分支的尖端在其远程对应的后面。回顾过去,这很有意义,因为我当前在本地分支的索引1上,而头部在远程的索引3上。

我现在要做的基本上是将分支的压缩版本(我在本地拥有)替换远程的非压缩版本。这里正确的方法是什么?

我已经看过这个,还有其他几个,但他们没有帮助。

jon*_*ten 5

您需要添加--force到建议的命令:

git push --set-upstream --force origin [BRANCH-NAME]
Run Code Online (Sandbox Code Playgroud)

使用来运行它之后--set-upstream,您便可以从那时开始键入git push(或git push -f在需要时输入)。