【发布时间】:2019-11-25 14:52:22
【问题描述】:
长话短说,我有一个正在开发的远程分支 (my-remote-branch),但它在 CI 中的一些测试失败了。我被告知要 rebase 到 master 来解决这个问题。
我做了以下事情:
git checkout master
git pull
git checkout my-remote-branch
git rebase master
git push
那时我得到一个错误:
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.
所以接下来我做了:
git pull --set-upstream-origin my-remote-branch
git push
这种只是造成了混乱。我的拉取请求现在有大量的提交(所有来自 master 的提交),所以历史都一团糟,拉取请求的更改文件数量令人误解。这似乎比简单的还原更复杂,因为我不能只还原到一个提交,所有提交都从 master 交织在一起。
显然我应该这样做是:
git fetch origin master
git rebase -I origin/master
git push —force
有什么方法可以撤消我的错误(撤消合并,仅从我的分支的历史记录中删除提交),以便我可以执行我应该执行的步骤?
【问题讨论】:
-
--set-upstream-origin不是git pull的选项。--set-upstream,没有-origin部分,是git push的一个选项。-force应该是--force(Git 对破折号的数量很挑剔),-I应该是-i(Git 对大小写也很挑剔)。最后两个可能只是拼写错误,但我不想猜测上面哪些命令有简单的拼写错误,哪些有更严重的奇怪之处,所以如果你在你的问题中理顺这些命令会很有帮助......跨度>
标签: git