如何在交互式编辑期间从 vim 内部中止 git rebase

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27226886/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:42:33  来源:igfitidea点击:

How to abort a git rebase from inside vim during interactive editing

gitvimgit-rebase

提问by René Link

When I do an interactive rebase, e.g.

当我进行交互式 rebase 时,例如

git rebase -i HEAD~3

the rebase interactive editor (vim in my case) opens to let me edit the commits to rebase

rebase 交互式编辑器(在我的例子中是 vim)打开让我编辑对 rebase 的提交

pick c843ea2 Set Vim column limit to 80 (OS X)
pick fc32eac Add Bash alias for `pbcopy` (OS X)
....

If I now decide that I want to abort the rebase and quit vim using :qthe rebase starts anyway. I'm using git version 1.9.0.msysgit.0on windows.

如果我现在决定要中止 rebase 并使用:qrebase 启动退出 vim 。我1.9.0.msysgit.0在 Windows 上使用 git 版本。

Sure I can just delete all picklines, but it might be a lot to do if I rebase a longer history. Is there another way?

当然我可以删除所有pick行,但如果我重新设置更长的历史记录,可能会有很多事情要做。还有其他方法吗?

How can I quit the rebase interactive editor (vim) and abort the rebase?

如何退出 rebase 交互式编辑器 (vim) 并中止 rebase?

回答by Telmo Costa

If you exit the editor with an error code, the rebase will be aborted.

如果您以错误代码退出编辑器,则 rebase 将中止。

To exit with an error code on vim, do

要在 vim 上以错误代码退出,请执行

:cq

See hereand vimdoc here.

请参阅此处和 vimdoc此处

回答by Steven Penny

Just delete all the lines that are not comments from the file. Then save it to the default supplied path and exit the editor.

只需从文件中删除所有不是注释的行。然后将其保存到默认提供的路径并退出编辑器。

As a result git will just do nothing in this rebase.

结果 git 在这个 rebase 中什么也不做。

To delete all lines in vim you can use

要删除 vim 中的所有行,您可以使用

:%d|x

Then save and quit.

然后保存退出。

delete all lines of file in Vim

删除 Vim 中的所有文件行

How to exit the Vim editor?

如何退出 Vim 编辑器?

VIM - multiple commands on same line

VIM - 同一行上的多个命令

回答by CodeManX

If you're using Notepad++ on Windows for instance:

例如,如果您在 Windows 上使用 Notepad++:

CtrlAto select everything, then Delor Backspaceto delete and CtrlSsave. Git will abort the rebase if the file is empty.

CtrlA选择所有内容,然后DelBackspace删除并CtrlS保存。如果文件为空,Git 将中止变基。

You may also hit CtrlCin the command prompt where git is running to stop the current rebase command. Then run git rebase --abortto revert it.

您也可以CtrlC在 git 运行的命令提示符中点击以停止当前的 rebase 命令。然后运行git rebase --abort以恢复它。

回答by mcandre

Delete all text in your text editor screen, then save the file with the default supplied path.

删除文本编辑器屏幕中的所有文本,然后使用默认提供的路径保存文件。