magit 变基使用 $EDITOR=vim

magit rebasing uses $EDITOR=vim

我为 windows 安装了 emacs 和 git(必须使用 windows 工作),当我提交时一切似乎都正常,评论消息很好地弹出 emacs,但是当变基时,我从 magit select 'interactively',我选择一个变基的提交,然后我按 'C-c C-c',它应该切换到 git-rebase-todo 缓冲区,但我得到的是 magit-process 缓冲区,似乎 git 尝试使用 vim 并卡在那里:

run C:/Program Files/Git/mingw64/libexec/git-core/git.exe … "rebase" "-i" "55ec1e8^"
Vim: Warning: Output is not to a terminal
Vim: Warning: Input is not from a terminal

Press ENTER or type command to continue[?1000l[?25h

似乎 magit 在变基时没有修改 $EDITOR,如何强制 magit 使用 emacs?谢谢。

我想通了,这与windows无关,我在gitconfig中有sequence.editor选项,看来magit无法覆盖这个选项。

确保 Git 2.34(2021 年第 4 季度),尤其是 Windows:在 Git 操作期间启动的编辑器会话(例如在 'git commit'(man 期间)) 或 git rebase 可以让终端处于有趣的状态。

The code path has updated to save the terminal state before, and restore it after, it spawns an editor.

参见 commit 3d411af, commit e22b245 (05 Oct 2021) by Carlo Marcelo Arenas Belón (carenas)
(由 Junio C Hamano -- gitster -- in commit 853ec9a 合并,2021 年 10 月 18 日)

editor: save and reset terminal after calling EDITOR

Signed-off-by: Carlo Marcelo Arenas Belón

When EDITOR is invoked to modify a commit message, it will likely change the terminal settings, and if it misbehaves will leave the terminal output damaged as shown in a recent report from Windows Terminal (issue 9359)

Instead use the functions provided by compat/terminal to save the settings and recover safely.

您可能遇到的错误示例: