git 完全取消rebase
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22289345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Completely cancel a rebase
提问by Graham Hymanson
I performed a rebase like this:
我执行了这样的变基:
git rebase --onto master new_background_processing export_background_processing
That didn't do what I wanted it to, so I performed a reset:
这并没有达到我想要的效果,所以我进行了重置:
git reset --hard HEAD@{1}
I got my branch back to the state it was, but I received this message when I type git status:
我让我的分支恢复到原来的状态,但是当我输入 git status 时我收到了这条消息:
# You are currently rebasing branch 'export_background_processing' on 'e378641'.
How do I cancel that rebase completely? Not sure what that means per se.
如何完全取消该变基?不确定这本身意味着什么。
回答by
Use git rebase --abort
. From the official Linux kernel documentation for git rebase
:
使用git rebase --abort
. 来自官方 Linux 内核文档git rebase
:
git rebase --continue | --skip | --abort | --edit-todo
回答by VonC
In the case of a past rebase that you did not properly aborted, you now (Git 2.12, Q1 2017) have git rebase --quit
如果您没有正确中止过去的变基,您现在(Git 2.12,2017 年第一季度)有 git rebase --quit
See commit 9512177(12 Nov 2016) by Nguy?n Thái Ng?c Duy (pclouds
).
(Merged by Junio C Hamano -- gitster
--in commit 06cd5a1, 19 Dec 2016)
请参阅Nguy?n Thái Ng?c Duy ( ) 的提交 9512177(2016 年 11 月 12 日)。
(由Junio C Hamano合并-- --在commit 06cd5a1,2016 年 12 月 19 日)pclouds
gitster
rebase
: add--quit
to cleanup rebase, leave everything else untouchedThere 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 normallyrm -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
".
rebase
: 添加--quit
到清理变基中,保留其他所有内容不变有时您决定中止正在进行的 rebase 并继续做其他事情,但您忘记先执行 "
git rebase --abort
"。或者 rebase 已经进行了很长时间,你忘记了。当您意识到(例如,通过开始另一个变基)时,回溯您的步骤已经为时已晚。解决方法通常是rm -r .git/<some rebase dir>
并继续你的生活。
但是可能有两个不同的目录<some rebase dir>
(并且显然需要了解 rebase 的工作原理),.git
如果您不在顶级目录或链接的工作树中,“ ”部分可能会更长。而“rm -r
”.git
在里面做是很危险的,在那里出错可能会破坏对象数据库或其他重要数据。
git rebase --quit
为这个用例提供“ ”,模仿“git cherry-pick --quit
”的先例。
Before Git 2.27 (Q2 2020), The stash entry created by "git merge --autostash
" to keep the initial dirty state were discarded by mistake upon "git rebase --quit
", which has been corrected.
在 Git 2.27(2020 年第 2 季度)之前,“ git merge --autostash
”为保持初始脏状态而创建的存储条目在“ ”上被错误丢弃git rebase --quit
,已更正。
See commit 9b2df3e(28 Apr 2020) by Denton Liu (Denton-L
).
(Merged by Junio C Hamano -- gitster
--in commit 3afdeef, 29 Apr 2020)
请参阅Denton Liu ( )提交的 9b2df3e(2020 年 4 月 28 日)。(由Junio C Hamano合并-- --在3afdeef 提交中,2020 年 4 月 29 日)Denton-L
gitster
rebase
: save autostash entry intostash reflog
on--quit
Signed-off-by: Denton Liu
In a03b55530a("
merge
: teach --autostash option", 2020-04-07, Git v2.27.0 -- mergelisted in batch #5), the--autostash
option was introduced forgit merge
.
rebase
: 将 autostash 条目保存到stash reflog
on--quit
签字人:Denton Liu
在a03b55530a(“
merge
:teach --autostash 选项”,2020-04-07,Git v2.27.0 --批处理#5 中列出的合并)中,为.--autostash
git merge
(See "Can “git pull
” automatically stash and pop pending changes?")
(参见“可以“ git pull
”自动隐藏和弹出挂起的更改吗?“)
Notably, when
git merge --quit
is run with an autostash entry present, it is saved into the stash reflog.This is contrasted with the current behaviour of
git rebase --quit
where the autostash entry is simply just dropped out of existence.Adopt the behaviour of
git merge --quit
ingit rebase --quit
and save the autostash entry into the stash reflog instead of just deleting it.
值得注意的是,当
git merge --quit
运行时存在 autostash 条目,它会保存到 stash reflog 中。这与
git rebase --quit
autostash 条目只是不存在的当前行为形成鲜明对比。采用
git merge --quit
in的行为git rebase --quit
并将 autostash 条目保存到 stash reflog 中,而不是仅仅删除它。
回答by vonbrand
You are lucky that you didn't complete the rebase, so you can still do git rebase --abort
. If you had completed the rebase (it rewrites history), things would have been much more complex. Consider tagging the tips of branches before doing potentially damaging operations (particularly history rewriting), that way you can rewind if something blows up.
你很幸运,你没有完成 rebase,所以你仍然可以做git rebase --abort
. 如果你已经完成了 rebase(它重写了 history),事情会复杂得多。在进行潜在的破坏性操作(特别是历史重写)之前,考虑标记分支的提示,这样你就可以在发生某些事情时倒带。
回答by Almas Adilbek
If you are "Rebasing", "Already started rebase"which you want to cancel, just comment (#)
all commits listed in rebase editor.
如果您要取消“Rebase”、“Already started rebase”,只需注释rebase 编辑器中列出的所有提交。(#)
As a result you will get a command line message
结果,您将收到一条命令行消息
Nothing to do