如何压制`git rebase --continue`的编辑器?

sla*_*dan 12 git macos command-line git-rewrite-history

我经常重新定义交互式以在历史记录中进行微小的更改(例如删除空白行或编辑一行).在大多数情况下,这些变化是基于一些同行评审.

起初我做这样的改变:

git rebase --interactive 83bbeb27fcb1b5e164318fa17c55b7a38e5d3c9d~
# replace "pick" by "edit" on the first line
# modify code
git commit --all --amend --no-edit
git rebase --continue
Run Code Online (Sandbox Code Playgroud)

如果以下提交之一中存在合并冲突,我将解决它们并执行此操作:

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
...
Run Code Online (Sandbox Code Playgroud)

是否有类似的--no-edit参数git rebase --continue可以避免编辑器(类似git commit)?

小智 18

作为编辑器使用的技巧true也可以通过 git 别名来完成,如下所示:

[alias]
    continue = "-c core.editor=true rebase --continue"
Run Code Online (Sandbox Code Playgroud)

然后你用git continue代替git rebase --continue.


Von*_*onC 9

我试过;(像那样:) GIT_EDITOR=true;git rebase --continue,但那没用.
(我正在使用mac)

GIT_EDITOR=true;
Run Code Online (Sandbox Code Playgroud)

这将GIT_EDITOR在当前的shell会话中设置,以便遵循所有命令.

使用:

GIT_EDITOR=true git rebase --continue
Run Code Online (Sandbox Code Playgroud)

它将GIT_EDITOR值作为环境变量传递给git命令分叉的子shell.

  • 像“var=val”这样设置环境变量仅适用于 shell。为了使 ti 适用于之后启动的所有进程,您需要调用“export var”。作为单个命令执行所有操作可以是“export var=val”。但对于“git”的所有其他调用覆盖“GIT_EDITOR”将是个坏主意。所以最后的建议(`var=val command`)是最好的,因为它没有负面影响。 (2认同)