linux 终端上的 Git 提交消息

Sco*_*ttF 6 linux git terminal

我正在尝试学习如何在 linux 终端上编写 git commit 消息。

编写提交消息后,我会看到以下选项。

哪个是我应该选择的第一个?

> ^G Get Help  ^O Write Out ^W Where Is  ^K Cut Text  ^J Justify   ^C Cur Pos
^X Exit      ^R Read File ^\ Replace   ^U Uncut Text^T To Spell  ^_ Go To Line
Run Code Online (Sandbox Code Playgroud)

如果我点击“写出”,我会得到另一个我不明白的选项列表。

File Name to Write:$T_EDITMSG                                                   
^G Get Help     M-D DOS Format  M-A Append      M-B Backup File
^C Cancel       M-M Mac Format  M-P Prepend     ^T To Files
Run Code Online (Sandbox Code Playgroud)

shi*_*zhz 6

这是因为 git 选择nano作为它的默认终端编辑器,如果你不熟悉 nano,你可以配置 git 使用另一个。

在终端中编写 git commit 消息的最简单方法是使用-m选项:

> git commit -m "your commit message"
Run Code Online (Sandbox Code Playgroud)

但是如果你没有指定-m选项,git 会把你带到一个编辑器取决于以下规则

  • Git 配置选项core.editor,首先是本地配置,然后是全局配置。

    • 本地:git config core.editor vim,配置驻留在文件 $YOUR_REPO/.git/config 中
    • 全局:git config --global core.editor vim,配置驻留在文件 $HOME/.gitconfig 中

    详情请参考Git 配置

  • 环境变量 $EDITOR 或 $VISUAL

    • export EDITOR=`which vim`
    • export VSUAL=`which emacs`

    这也是其他工具在需要编辑器时使用的设置。