[英]Start text of git commit with the text of the parent commit
当您在 git 中创建新提交时,您可以通过指定git commit -t <filename>
或commit.template
环境变量来指定您希望提交消息编辑器以文件内容启动。 有没有办法指定您始终希望使用父提交的全文作为模板?
上下文:与许多其他代码库一样,我通常的代码库需要对提交所处理的错误/问题进行注释,以便在每次提交中出现。 记住错误/问题编号很困难,而且我经常有一堆关于同一主题的提交,要按顺序提交。 使用像git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V
这样的咒语很尴尬git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V
git commit; Ctrl+Z; g log -1; <click>; Shift+Ctrl+C; fg; Shift+Ctrl+V
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
相关的在线文档项目是:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--Cltcommitgt
-C
--reuse-message=<提交>获取现有的提交对象,并在创建提交时重用日志消息和作者信息(包括时间戳)。
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--e
-e
- 编辑从带有-F 的文件、带有-m 的命令行以及带有-C 的提交对象中获取的消息通常用作未修改的提交日志消息。 此选项可让您进一步编辑从这些来源获取的消息。
正如@KevinReid 所建议的:
https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---reset-author
--重置作者
当与-C/-c/--amend选项一起使用时,或者在发生冲突的cherry-pick 之后提交时,声明结果提交的作者现在属于提交者。 这也会更新作者时间戳。
如果你想让这个命令更实用,例如通过依赖一个 env。 变量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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.