Git interactive rebase without opening the editor

半世苍凉 提交于 2019-11-29 01:16:26

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

As an illustration of torek's solution (GIT_SEQUENCE_EDITOR=:) see Git 2.21 (Feb. 2019):

When GIT_SEQUENCE_EDITOR is set, the command was incorrectly started when modes of "git rebase" that implicitly uses the machinery for the interactive rebase are run, which has been corrected.

See commit 891d4a0 (28 Jan 2019) by Phillip Wood (phillipwood).
(Merged by Junio C Hamano -- gitster -- in commit 69dd6e5, 05 Feb 2019)

implicit interactive rebase: don't run sequence editor

If GIT_SEQUENCE_EDITOR is set then rebase runs it when executing implicit interactive rebases which are supposed to appear non-interactive to the user.
Fix this by setting GIT_SEQUENCE_EDITOR=: rather than GIT_EDITOR=:.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!