130

我通过交互式 rebase 让自己陷入了混乱,我现在希望中止它。(即回到我进入交互式变基模式之前的点,在我的例子中是 via git pull --rebase。)这样做的方法似乎是 via git rebase --abort,但这不起作用:

$ git rebase --abort
error: Ref refs/heads/master is at 55b388c141b1485b1acd9e050dbeb0eb90ef2ee7 but
expected b918ac16a33881ce00799bea63d9c23bf7022d67
fatal: Cannot lock the ref 'refs/heads/master'.
Could not move back to refs/heads/master

我怎样才能摆脱交互式变基模式,并清理对它的所有引用?(git reset --hard成功,但不会让我退出变基模式。)

4

2 回答 2

87

尝试遵循您在屏幕上看到的建议,并首先将您的主人的 HEAD 重置为它期望的提交。

git update-ref refs/heads/master b918ac16a33881ce00799bea63d9c23bf7022d67

然后,再次中止变基。

于 2011-02-24T12:38:31.070 回答
1

使用 Git 2.34(2021 年第四季度), agit rebase --abort应该更可靠:

" git rebase <upstream> <tag>" ( man )在中间中止时失败,因为它错误地尝试写入标签对象而不是将其剥离到 HEAD。

请参阅提交 7740ac6提交 1d18826提交 35f070b(2021 年 9 月 21 日)和提交 d045719提交 1e14bc1提交 0b7ae73提交 54627db提交 7390c65提交 e505f45提交 f20c1fb phillipwood 2021 年 9 月 13 日)菲利普伍德。
(由Junio C Hamano 合并 -- gitster--提交 7cebe73中,2021 年 10 月 6 日)

rebase: 取消引用标签

签字人:菲利普·伍德

git rebase <A> <B>以 ' ' ( man )开头的变基在概念上是首先checkout <B>git rebase <A>从该状态开始运行。
' git rebase --abort' ( man )在这样一个变基的中间应该带我们回到我们检查出来的状态<B>

这曾经有效,即使<B>是指向提交的标记,直到 Git 2.20.0 重新实现命令时C
该命令现在抱怨无法签出标记对象本身,这在技术上可能是正确的,但不是用户要求做的。

通过使用lookup_commit_reference_by_name()when parsing修复这个旧的回归<B>
脚本版本不需要剥离标签,因为它传递标签的命令(例如' git reset' man)会自行剥离标签。

于 2021-10-10T15:18:38.027 回答