没有打开编辑器的Git交互式底图 [英] Git interactive rebase without opening the editor
问题描述
git commit --amend --no-edit
git commit --fixup = HEAD ^
code> rebase.autosquash 改为 true
,这样交互式rebase的todo列表会自动重新排序。有没有办法立即执行rebase,而无需先打开编辑器,如下所示:
git rebase -i --no -edit HEAD〜3
TL; DR答案: GIT_SEQUENCE_EDITOR =:git rebase -i HEAD〜3
你不能停止 git rebase - 交互
运行序列编辑器(这是序列文件中包含各种选择等命令的编辑命令)。但是,如果您检查交互式rebase脚本:
$ vim $(git --exec-path)/ git-rebase- -interactive
你可以在230行左右找到这样的代码:
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)||返回$?
fi
fi
eval$ GIT_SEQUENCE_EDITOR'$ @'
}
因此,您只需将序列编辑器设置为一个编辑命令,它不执行任何操作,然后成功执行,例如shell的内置: 命令或
true
命令。
< > $ GIT_SEQUENCE_EDITOR ,配置的
sequence.editor
或 $ GIT_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
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.)
这篇关于没有打开编辑器的Git交互式底图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!