格式化来自 shell 的 GitHub 提交消息

Formatting GitHub commit messages from shell

我刚读完 Writing good commit messages 并且非常喜欢。问题是,我更喜欢命令行 (plain ole' git).

  1. 对于换行,只需在引号内输入,如下所示:git commit -m "Some headline <hit enter>。您也可以使用 your text editor to write commit messages.

  2. 很遗憾没有,例如例如this commit with markdown

git 会在您 运行 git commit 时自动生成您的首选 $EDITOR 以提示提交消息。所以它可能就像离开 -m 一样简单 git commit 命令

如果 git 启动了错误的编辑器,或者无法启动编辑器,请尝试将 EDITOR 环境变量设置为您首选的编辑器:

export EDITOR=/usr/bin/vim

或者,要仅更改 git 使用的编辑器,您可以设置 core.editor

git config --global core.editor /usr/bin/vim

使用编辑器以这种方式编写提交消息还有一些其他优点。 Git 使用提交中更改的文件的摘要填充您正在编辑的文件,这应该可以帮助您编写更好的提交消息。此外,vim(和其他编辑器)支持此类文件的基本语法突出显示,使其更容易。

创建git提交时,您可以多次使用-m,它会创建多个段落。

引用 man page

-m <msg>, --message=<msg>

Use the given as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs

此外,如前所述,如果您省略 -m 选项,那么 git 将打开一个编辑器(使用类似 git config --global core.editor /usr/bin/vim 的命令设置),您可以在其中输入您的提交消息.