Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.3k views
in Technique[技术] by (71.8m points)

How to prevent the standard git merge editor from being used in the VS Code terminal?

I like to use the command line for issuing git commands as much as possible, but when a merge occurs, emacs is launched per my settings. If this happens in the VS Code Terminal, key bindings are not going to work well. Is there a way to have the VS Code terminal configured so that VS Code itself is used as the merge editor (but only when git is called from the VS Code terminal)?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can detect the TERM_PROGRAM in your ~/.bashrc or for that matter ~/.zshrc depending on your shell:

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

Looking at man git-commit you can see how git picks the appropriate editor, and you might want to simply set the EDITOR environment variable instead of GIT_EDITOR as other programs would benefit from this as well:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...