【问题标题】:Is it possible to change Git standard messages when committing?提交时是否可以更改 Git 标准消息?
【发布时间】:2012-11-22 09:11:23
【问题描述】:
是否可以更换零件:
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
说:
# Staged:
【问题讨论】:
标签:
git
githooks
git-commit
【解决方案1】:
简单来说,就是那部分,不。
但是您可以使用 commit-msg 挂钩来修改提交消息。
【解决方案2】:
是的,使用prepare-commit-msg 挂钩。这是.git/hooks/ 中的一个脚本,它在 Git 生成提交消息和在编辑器中打开提交消息之间运行。
作为一个简单的示例,将以下文本复制到 .git/hooks/ 中名为 prepare-commit-msg 的新文件中。
#!/bin/sh
sed -i '0,/# Changes to be committed:/c# Staged:' "$1"
如果您发现它不能立即运行,请检查它的可执行性:运行chmod +x .git/hooks/prepare-commit-msg。
(该脚本是一个sed 单行代码,用文本“# Staged:”替换每一行,包括“要提交的更改”行)