首页 > 解决方案 > 如何防止在 VS Code 终端中使用标准的 git 合并编辑器?

问题描述

我喜欢尽可能多地使用命令行来发出 git 命令,但是当发生合并时,emacs会根据我的设置启动。如果这发生在 VS Code 终端中,键绑定将无法正常工作。有没有办法配置 VS Code 终端,以便将 VS Code 本身用作合并编辑器(但仅在git从 VS Code 终端调用时)?

标签: gitvisual-studio-code

解决方案


您可以根据您的外壳检测到TERM_PROGRAM您的~/.bashrc或就此而言:~/.zshrc

if [ "$TERM_PROGRAM" = "vscode" ]
then
  export GIT_EDITOR="code"
else
  export GIT_EDITOR="emacs"
fi

看着man git-commit你可以看到 git 如何选择合适的编辑器,你可能想简单地设置EDITOR环境变量,而不是GIT_EDITOR其他程序也会从中受益:

$ man git-commit | awk '/core.editor/' RS=
ENVIRONMENT AND CONFIGURATION VARIABLES
       The editor used to edit the commit log message will be chosen from the
       GIT_EDITOR environment variable, the core.editor configuration
       variable, the VISUAL environment variable, or the EDITOR environment
       variable (in that order). See git-var(1) for details.

推荐阅读