git rebase --editor=/something/other/than/vim? (for easier squashing)

22,441

Solution 1

Try adding the GIT_EDITOR environment variable before your command, like so:

GIT_EDITOR=<editor of choice> git rebase <...>

For example, to use nano I would type:

GIT_EDITOR=nano git rebase -i abcdef1234

Solution 2

There is an even better option for all your interactive rebase.

https://github.com/sjurba/rebase-editor

It is a custom CLI app written in node specifically for interactive rebase.

To install:

npm install -g rebase-editor
git config --global sequence.editor rebase-editor 

Or with yarn:

yarn global add rebase-editor
git config --global sequence.editor rebase-editor 
Share:
22,441
Sridhar Sarnobat
Author by

Sridhar Sarnobat

Updated on August 22, 2020

Comments

  • Sridhar Sarnobat
    Sridhar Sarnobat almost 4 years

    I happily use vim as my default editor for commits, and do not wish to change it. However, when it comes to rebasing, I find myself squashing dozens and dozens of commits which I find much easier with an interactive editor like Textwrangler (substituting "pick" with "squash" in all but the top commit).

    Is there any way to specify an alternate editor for a one-off rebase command?

    I know in vim I can do:

    :%s/pick/squash/
    

    but that has its own minor annoyances.

    EDIT - as stated in the comments, you can squash all but the top commit very efficiently by going to the 2nd line and executing

    :,$s/pick/squash/
    

    (note the comma and dollar are different to the original)

  • Sridhar Sarnobat
    Sridhar Sarnobat over 10 years
    Since you aren't exporting it, does that variable value get reset when the command terminates? (that would be ideal, but I'm guessing you need to reset it manually)
  • Rob Bajorek
    Rob Bajorek over 10 years
    The variable is only set for that one command invocation. Try running git rebase again without GIT_EDITOR and you'll use your default editor again.
  • Sridhar Sarnobat
    Sridhar Sarnobat over 10 years
    Awesome, this is the right answer then. Though I think my fears of learning a bit more vim were irrational
  • MarkHu
    MarkHu about 8 years
    Awesome indeed. For some reason my ancient server-side OS defaulted to vi instead of vim --so now I know how to perma-fix this.
  • Antony Stubbs
    Antony Stubbs about 5 years
    dang this tool is awesome sauce
  • Bobby Axe
    Bobby Axe about 4 years
    This helped me a lot thanks, i believe a lot of people are looking for GIT_EDITOR=nano git rebase -i @~9 this will show your last nine commits and you should be able to modify them.
  • EddyXorb
    EddyXorb over 3 years
    For visual code use GIT_EDITOR="code --wait" git rebase -i abfa452
  • Dan Ciborowski - MSFT
    Dan Ciborowski - MSFT over 2 years
    This tool is now required part of my setup. Being able to select each action with the single press of a key makes "git rebase" a teachable process.