Git:取消交互式rebase

时间:2015-11-06 01:05:46

标签: git vim rebase

我喜欢git rebase -i HEAD~5来压缩我的承诺。有时我认为我需要返回5次提交但后来意识到我需要7.但是git已经在vim中提出了rebase编辑器.git/rebase-merge/git-rebase-todo

如果我退出缓冲区(vim),那么git说:

Successfully rebased and updated refs/heads/my-branchname

有没有办法在编辑器中停止使用rebase?我想我可以从另一个shell git rebase --abort但不确定对git-rebase-todo文件做什么,我将在另一个缓冲区中编辑。

2 个答案:

答案 0 :(得分:12)

如果您在初始交互式rebase编辑器窗口中,如下所示:

pick f7f3f6d changed my name a bit
pick 310154e updated README formatting and added blame
pick a5f4a0d added cat-file

# Rebase 710f0f8..a5f4a0d onto 710f0f8
...
...
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.

您可以通过删除编辑器窗口的全部内容并保存它来中止rebase,或者使编辑器关闭并显示错误代码。

在vim中,可以使用d SHIFT+g后跟:wq来完成,或者使编辑器退出时出现错误,正如Mike H-R使用:cq指出的那样。

如果您已离开该窗口并正在进行下面的压缩/编辑/等,则不会中止整个rebase,而只会中止当前正在编辑的提交的更改。此时您可以按上述方式终止编辑器,但此外您还必须在命令行上执行git rebase --abort

答案 1 :(得分:8)

您可以使用非零退出代码使vim退出,以通过键入:cq来取消rebase。结果是:

$ git rebase -i HEAD~4
# enter vim, then type :cq<enter>
Could not execute editor

在vim帮助页面中,我们看到cq是cquit的缩写:

                                                        *:cq* *:cquit*
:cq[uit][!]             Quit Vim with an error code, so that the compiler
                        will not compile the same file again.
                        WARNING: All changes in files are lost!  Also when the
                        [!] is not used.  It works like ":qall!" |:qall|,
                        except that Vim returns a non-zero exit code.