【问题标题】:Undo git merge to remote branch撤消 git 合并到远程分支
【发布时间】: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


【解决方案1】:

您可以使用

撤消上次提交
git checkout my-remote-branch
git reset --hard HEAD~1

source

如果最后一次提交不是“坏”的,那么你可以使用git log 找到最后一次好的提交的最后一个哈希然后做

git reset --hard HASH

(用相应的哈希替换HASH)。


之后,您又回到了起点,可以做您认为正确的事情。

【讨论】:

    猜你喜欢
    • 2021-06-26
    • 2020-04-12
    • 2013-11-21
    • 1970-01-01
    • 2019-03-17
    • 1970-01-01
    • 2011-12-18
    • 2013-05-23
    • 2020-04-04
    相关资源
    最近更新 更多