Git interactive rebase without opening the editor

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.)

Leave a Comment