Git:取消交互式rebase

Mel*_*emi 12 git vim rebase

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

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

Successfully rebased and updated refs/heads/my-branchname
Run Code Online (Sandbox Code Playgroud)

有没有办法在编辑器中停止转换?我想我可以git rebase --abort从另一个shell,但不知道这会对git-rebase-todo我在另一个缓冲区中编辑的文件做什么.

wha*_*erg 15

如果您在初始交互式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.
Run Code Online (Sandbox Code Playgroud)

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

在vim中,这可以通过d SHIFT+g后面的方式完成:wq,或者可选地使编辑器以Mike HR指出的错误退出:cq.

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


Mik*_*H-R 12

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

$ git rebase -i HEAD~4
# enter vim, then type :cq<enter>
Could not execute editor
Run Code Online (Sandbox Code Playgroud)

在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.
Run Code Online (Sandbox Code Playgroud)

  • 好,我咬一口;什么是`:cq`? (2认同)