Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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)

like image 304
Sridhar Sarnobat Avatar asked Oct 31 '13 18:10

Sridhar Sarnobat


People also ask

How do you squash commits with rebase interactive?

Squash commits together. Two other commands rebase interactive offers us are: squash ( s for short), which melds the commit into the previous one (the one in the line before) fixup ( f for short), which acts like “squash”, but discards this commit's message.

Why you should not use git rebase?

Rebasing can be dangerous! Rewriting history of shared branches is prone to team work breakage. This can be mitigated by doing the rebase/squash on a copy of the feature branch, but rebase carries the implication that competence and carefulness must be employed.

How do I save squash in git?

Git will open another file where you have to enter a new commit message for the two commits you squash . Lines starting with # are comments that are there to guide you. Delete both the commit messages and add a new one. Press Esc , type :wq! and press Enter to save and exit.


1 Answers

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 
like image 176
Rob Bajorek Avatar answered Oct 06 '22 12:10

Rob Bajorek