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

56,694

Solution 1

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.

Solution 2

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

Solution 3

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

CtrlA to select everything, then Del or Backspace to delete and CtrlS save. Git will abort the rebase if the file is empty.

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

Solution 4

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

Share:
56,694

Related videos on Youtube

René Link
Author by

René Link

If you want the other to take you serious, take your craft serious - be a professional. I'm a software developer since 2002 and founded Link Intersystems in 2011. My favorite programming language is Java, but I'm also experienced in other languages. I focus on design, architecture and clean code. Check out my blog at http://www.link-intersystems.com/blog/ My code at github https://github.com/link-intersystems My youtube channel (german) My code at codepen.io www.datanect.com - a data analysis tool Visit me on careers https://careers.stackoverflow.com/renelink

Updated on July 08, 2022

Comments

  • René Link
    René Link almost 2 years

    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?

    • Zombo
      Zombo over 9 years
      Would you prefer to use a different editor, such as Notepad? If so, I have a solution for that
    • vanduc1102
      vanduc1102 almost 7 years
      git rebase --abort
    • C Bauer
      C Bauer over 5 years
      @vanduc1102 Works for me, wish it was an answer!
  • Mladen B.
    Mladen B. over 5 years
    this is not the case for the merge commits. try doing the interactive rebase to include at least one merge commit and compare the result with the original state.
  • Mladen B.
    Mladen B. over 5 years
    this is the general way to solve this problem, no matter if you're using vim or any other editor. thanks a lot! :)