Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git interactive rebase without opening the editor

Git allows certain commands to create or modify commits without opening the editor first, for example:

git commit --amend --no-edit git commit --fixup=HEAD^ 

I have set rebase.autosquash to true, so that the todo list for an interactive rebase is automatically reordered. Is there a way to immediately perform the rebase, without opening the editor first, something like:

git rebase -i --no-edit HEAD~3 
like image 498
friederbluemle Avatar asked Mar 17 '15 08:03

friederbluemle


People also ask

How do you go into interactive mode in rebase?

Changing Multiple Commit Messages You can run rebase interactively by adding the -i option to git rebase . You must indicate how far back you want to rewrite commits by telling the command which commit to rebase onto.

How do I get out of rebase interactive?

Git Rebasing Aborting an Interactive Rebase To do this, simply delete all commits and actions (i.e. all lines not starting with the # sign) and the rebase will be aborted!

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.


2 Answers

TL;DR answer: GIT_SEQUENCE_EDITOR=: git rebase -i HEAD~3

You can't stop git rebase --interactive from running the "sequence editor" (that's the edit command on the "sequence file" containing the various pick, etc., commands). However, if you examine the interactive rebase script:

$ vim $(git --exec-path)/git-rebase--interactive 

you'll find code like this near line 230 or so:

git_sequence_editor () {     if test -z "$GIT_SEQUENCE_EDITOR"     then         GIT_SEQUENCE_EDITOR="$(git config sequence.editor)"         if [ -z "$GIT_SEQUENCE_EDITOR" ]         then             GIT_SEQUENCE_EDITOR="$(git var GIT_EDITOR)" || return $?         fi     fi      eval "$GIT_SEQUENCE_EDITOR" '"$@"' } 

Thus, you simply need to set the sequence editor to an "edit" command that does nothing and then succeeds, such as the shell's built-in : command, or the true command.

(Any of $GIT_SEQUENCE_EDITOR, the configured sequence.editor, or $GIT_EDITOR will suffice for this, though the obvious best one to use is the first.)

like image 134
torek Avatar answered Sep 20 '22 12:09

torek


Instead of using the GIT_SEQUENCE_EDITOR environment variable, you can use -c to pass configuration to git:

git -c sequence.editor=: rebase --autosquash --interactive origin/master 

Works well for triggering editor-free rebases from within your editor (i.e., using fugitive's :Git command in vim).

like image 42
idbrii Avatar answered Sep 16 '22 12:09

idbrii