Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

When I do an interactive rebase, e.g.

git rebase -i HEAD~3

the rebase interactive editor (vim in my case) opens to let me edit the commits to 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 :q the rebase starts anyway. I'm using git version 1.9.0.msysgit.0 on windows.

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

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

like image 600
René Link Avatar asked Oct 05 '22 01:10

René Link


People also ask

How do I cancel an interactive rebase?

To do this, simply delete all commits and actions (i.e. all lines not starting with the # sign) and the rebase will be aborted!

How do I abort a rebase in git?

You can run git rebase --abort to completely undo the rebase. Git will return you to your branch's state as it was before git rebase was called. You can run git rebase --skip to completely skip the commit.

How do I edit a rebase interactive?

Just right-click on the commit you want to edit and select Interactively Rebase from Here… Select reword on the commit and click Start Rebasing. Edit the commit message and click Resume Rebasing.


Video Answer


2 Answers

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

To exit with an error code on vim, do

:cq

See here and vimdoc here.

like image 190
Telmo Costa Avatar answered Oct 09 '22 04:10

Telmo Costa


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.

To delete all lines in vim you can use

:%d|x

Then save and quit.

delete all lines of file in Vim

How to exit the Vim editor?

VIM - multiple commands on same line

like image 20
Zombo Avatar answered Oct 09 '22 02:10

Zombo