简体   繁体   中英

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

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)

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

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 

With Git 2.40 (Q1 2023), just like " git var GIT_EDITOR " ( man ) " abstracts the complex logic to choose which editor gets used behind it, " git var " now give support to GIT_SEQUENCE_EDITOR .

See commit 4c3dd93 (17 Dec 2022) by Sean Allred ( vermiculus ) .
(Merged by Junio C Hamano -- gitster -- in commit 48475f4 , 28 Dec 2022)

var : add GIT_SEQUENCE_EDITOR variable

Signed-off-by: Sean Allred

The editor program used by Git when editing the sequencer "todo" file is determined by examining a few environment variables and also affected by configuration variables.
Introduce " git var GIT_SEQUENCE_EDITOR " ( man ) " to give users access to the final result of the logic without having to know the exact details.

This is very similar in spirit to 44fcb49 (Teach git var about GIT_EDITOR , 2009-11-11, Git v1.6.6-rc0 -- merge ) that introduced " git var GIT_EDITOR ".

git var now includes in its man page :

GIT_SEQUENCE_EDITOR

Text editor used to edit the 'todo' file while running git rebase -i . Like GIT_EDITOR , the value is meant to be interpreted by the shell when it is used.

The order of preference is:

  • the $GIT_SEQUENCE_EDITOR environment variable, then
  • sequence.editor configuration, and then
  • the value of git var GIT_EDITOR .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM