2023-10-06 08:00:04

完全取消一次改基

我执行了一个rebase,就像这样:

git rebase --onto master new_background_processing export_background_processing

这并没有做我想做的,所以我执行了重置:

git reset --hard HEAD@{1}

我让我的分支回到了原来的状态,但当我输入git status时,我收到了这条消息:

# You are currently rebasing branch 'export_background_processing' on 'e378641'.

我怎么取消这个完全变基?不知道这本身意味着什么。


当前回答

如果你没有正确地放弃过去的重基,你现在(Git 2.12, 2017年第一季度)有Git重基-退出

参见提交9512177(2016年11月12日)由nguyeconn Thái ngeconc Duy (pclouds)。 (由Junio C Hamano—gitster—在commit 06cd5a1中合并,2016年12月19日)

rebase: add --quit to cleanup rebase, leave everything else untouched There are occasions when you decide to abort an in-progress rebase and move on to do something else but you forget to do "git rebase --abort" first. Or the rebase has been in progress for so long you forgot about it. By the time you realize that (e.g. by starting another rebase) it's already too late to retrace your steps. The solution is normally rm -r .git/<some rebase dir> and continue with your life. But there could be two different directories for <some rebase dir> (and it obviously requires some knowledge of how rebase works), and the ".git" part could be much longer if you are not at top-dir, or in a linked worktree. And "rm -r" is very dangerous to do in .git, a mistake in there could destroy object database or other important data. Provide "git rebase --quit" for this use case, mimicking a precedent that is "git cherry-pick --quit".


在Git 2.27 (Q2 2020)之前,“Git merge -autostash”为保持初始脏状态而创建的存储条目在“Git rebase -quit”时被错误丢弃,现已更正。

参见刘丹顿(Denton- l)提交的9b2df3e(2020年4月28日)。 (由Junio C Hamano—gitster—在commit 3afdeef中合并,2020年4月29日)

Rebase:保存自动存储入口到stash reflog on -quit 签署人:Denton Liu 在a03b55530a(“merge: teach——autostash选项”,2020-04-07,Git v2.27.0——merge在第5批中列出)中,为Git merge引入了——autostash选项。

(参见“git可以自动存储和弹出挂起的更改吗?”)

值得注意的是,当git merge -quit运行时带有一个autostash条目,它会被保存到stash reflog中。 这与当前git rebase -quit的行为形成了对比,其中autostash条目只是简单地从存在中消失。 采用git merge -quit in git rebase -quit的行为,并将autostash条目保存到stash reflog中,而不是直接删除它。

其他回答

如果你想取消“rebase”,“Already started rebase”,只需注释(#)rebase编辑器中列出的所有提交。

因此,您将得到一条命令行消息

Nothing to do

如果你没有正确地放弃过去的重基,你现在(Git 2.12, 2017年第一季度)有Git重基-退出

参见提交9512177(2016年11月12日)由nguyeconn Thái ngeconc Duy (pclouds)。 (由Junio C Hamano—gitster—在commit 06cd5a1中合并,2016年12月19日)

rebase: add --quit to cleanup rebase, leave everything else untouched There are occasions when you decide to abort an in-progress rebase and move on to do something else but you forget to do "git rebase --abort" first. Or the rebase has been in progress for so long you forgot about it. By the time you realize that (e.g. by starting another rebase) it's already too late to retrace your steps. The solution is normally rm -r .git/<some rebase dir> and continue with your life. But there could be two different directories for <some rebase dir> (and it obviously requires some knowledge of how rebase works), and the ".git" part could be much longer if you are not at top-dir, or in a linked worktree. And "rm -r" is very dangerous to do in .git, a mistake in there could destroy object database or other important data. Provide "git rebase --quit" for this use case, mimicking a precedent that is "git cherry-pick --quit".


在Git 2.27 (Q2 2020)之前,“Git merge -autostash”为保持初始脏状态而创建的存储条目在“Git rebase -quit”时被错误丢弃,现已更正。

参见刘丹顿(Denton- l)提交的9b2df3e(2020年4月28日)。 (由Junio C Hamano—gitster—在commit 3afdeef中合并,2020年4月29日)

Rebase:保存自动存储入口到stash reflog on -quit 签署人:Denton Liu 在a03b55530a(“merge: teach——autostash选项”,2020-04-07,Git v2.27.0——merge在第5批中列出)中,为Git merge引入了——autostash选项。

(参见“git可以自动存储和弹出挂起的更改吗?”)

值得注意的是,当git merge -quit运行时带有一个autostash条目,它会被保存到stash reflog中。 这与当前git rebase -quit的行为形成了对比,其中autostash条目只是简单地从存在中消失。 采用git merge -quit in git rebase -quit的行为,并将autostash条目保存到stash reflog中,而不是直接删除它。

你很幸运,你没有完成rebase,所以你仍然可以做git rebase -abort。如果您已经完成了重基(它重写历史),事情就会复杂得多。考虑在进行可能具有破坏性的操作(特别是历史重写)之前标记分支的尖端,这样如果出现问题,您就可以倒带。

使用git rebase -abort。来自git rebase的官方Linux内核文档:

git rebase --continue | --skip | --abort | --edit-todo | --quit