如何让 git 使用我选择的编辑器进行提交? [英] How do I make git use the editor of my choice for commits?

查看:32
本文介绍了如何让 git 使用我选择的编辑器进行提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我更喜欢在 Vim 中编写我的提交消息,但 git 正在 Emacs 中打开它们.

I would prefer to write my commit messages in Vim, but git is opening them in Emacs.

如何配置 git 以始终​​使用 Vim?请注意,我想在全局范围内执行此操作,而不仅仅是针对单个项目.

How do I configure git to always use Vim? Note that I want to do this globally, not just for a single project.

推荐答案

如果您想为 Git 设置only 编辑器,请执行任一操作(您不需要两者都需要):

If you want to set the editor only for Git, do either (you don’t need both):

  • 设置core.editor 在你的 Git 配置中:git config --global core.editor "vim"

  • 设置GIT_EDITOR 环境变量:<代码>导出 GIT_EDITOR=vim

如果您想为 Git 以及其他程序设置编辑器,请设置标准化的VISUALEDITOR环境变量*:

If you want to set the editor for Git and also other programs, set the standardized VISUAL and EDITOR environment variables*:

export VISUAL=vim
export EDITOR="$VISUAL"

注意:不一定需要同时设置,但有些程序可能不会使用更正确的VISUAL.参见 VISUALEDITOR>.

NOTE: Setting both is not necessarily needed, but some programs may not use the more-correct VISUAL. See VISUAL vs. EDITOR.

有些编辑器需要 --wait 标志,否则会打开一个空白页面.例如:

Some editors require a --wait flag, or they will open a blank page. For example:

  • Sublime Text(如果 正确设置;或使用可执行文件的完整路径代替subl):

  • Sublime Text (if correctly set up; or use the full path to the executable in place of subl):

export VISUAL="subl --wait"

VS Code(在添加 shell 命令):

export VISUAL="code --wait"

这篇关于如何让 git 使用我选择的编辑器进行提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆