git 提交的开始文本与父提交的文本

Start text of git commit with the text of the parent commit

当您在 git 中创建新提交时,您可以通过指定 git commit -t <filename> 或 [=12] 来指定您希望提交消息编辑器以文件内容启动=] 环境变量。有没有办法指定您始终希望使用父提交的全文作为模板?

上下文:与许多其他代码库一样,我常用的代码库需要注释 bug/issue 提交正在处理的内容,以便出现在每次提交中。记住 bug/issue 个数字很难,而且我经常有一堆关于同一主题的提交,要按顺序提交。使用像git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V这样的咒语很尴尬,这是我通常被迫做的。

你应该只需要 运行:

git commit -C HEAD --reset-author -e

或更一般地说:

git commit -C $TEMPLATE_COMMIT_SHA1 --reset-author -e

相关联机文档项目为:

如果你想让这个命令更实用,例如通过依赖环境。变量 TEMPLATE_COMMIT_SHA1,您可以定义一个 git 别名,例如:

# "committ" stands for "commit-template"
git config alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'

# or if you prefer to make this alias available for all repos:
git config --global alias.committ '!f(){ set -x; git commit -C "${TEMPLATE_COMMIT_SHA1:-HEAD}" --reset-author -e "$@"; }; f'

# demo
touch a; git add a; git committ

export TEMPLATE_COMMIT_SHA1=HEAD^^^
touch b; git add b; git committ