Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to suppress the editor for `git rebase --continue`?

I'm often rebasing interactive to make tiny changes in the history (for example removing a blank line, or editing one line). In most cases those changes are based on some peer review.

At first I do my change like that:

git rebase --interactive 83bbeb27fcb1b5e164318fa17c55b7a38e5d3c9d~ # replace "pick" by "edit" on the first line # modify code git commit --all --amend --no-edit git rebase --continue 

If there are merge conflicts in one of the following commits, I resolve them and do this:

git rebase --continue # the commit message is shown, but does not have to be changed, so I just save and exit the editor git rebase --continue # the commit message is shown, but does not have to be changed, so I just save and exit the editor git rebase --continue # the commit message is shown, but does not have to be changed, so I just save and exit the editor ... 

Is there anything like a --no-edit argument to git rebase --continue that avoids the editor (similar to git commit)?

like image 928
slartidan Avatar asked Apr 19 '17 08:04

slartidan


People also ask

How do I turn off rebase editor?

Press Esc , :wq! and Enter to save and exit. Now, rebase will stop at Added Mary commit. Next, make the country to Australia in Mary.

What is rebase continue git?

Git gets to the edit dd1475d operation, stops, and prints the following message to the terminal: You can amend the commit now, with git commit --amend Once you are satisfied with your changes, run git rebase --continue. At this point, you can edit any of the files in your project to make any additional changes.


1 Answers

First approach, through Git configuration:

git -c core.editor=true rebase --continue 

Or, with environment variables:

GIT_EDITOR=true git rebase --continue 

This will override the editor that git uses for message confirmation. true command simply ends with zero exit code. It makes git continue rebase as if user closed interactive editor.

On Windows, you would need to use CMD /V /C

cmd /V /C "set "GIT_EDITOR=true" && git rebase --continue 

In both OS, you can use aliases

# Linux alias grc='GIT_EDITOR=true git rebase --continue'  # Windows doskey grc=cmd /V /C "set "GIT_EDITOR=true" && git rebase --continue" 

Then a simple grc will be enough to continue the rebase without the editor popping up.


To set that globally (without alias), maybe consider this approach:

specifying the core.commentChar detected from the .git/rebase-merge/message (here @):

git --global core.commentChar @ 

There is also GIT_SEQUENCE_EDITOR=:, but you cannot always leave it at that value, because that would break all the rebase operation where you want an editor.

That is why having an alias remains the most flexible and accurate approach, rather than relying on a global setting which might break other rebase editor use cases.

like image 167
VonC Avatar answered Sep 17 '22 19:09

VonC