提交时是否可以更改Git标准消息?

时间:2012-12-04 17:01:23

标签: git githooks git-commit

是否可以更改部件:

# 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:

2 个答案:

答案 0 :(得分:5)

是的,使用prepare-commit-msg挂钩。这是.git/hooks/中的一个脚本,它在Git生成的提交消息和在编辑器中打开的提交消息之间运行。

举个简单的例子,将以下文字复制到prepare-commit-msg中名为.git/hooks/的新文件中。

#!/bin/sh
sed -i '0,/# Changes to be committed:/c# Staged:' "$1"

如果您发现它不能立即起作用,请检查它的可执行文件:运行chmod +x .git/hooks/prepare-commit-msg

(该脚本是一个sed单行代码,用“#Staged:”文本替换每行直到并包括“要提交的更改”行

答案 1 :(得分:0)

以一种简单的方式,只是那一部分,没有。

但是你可以使用commit-msg钩子来修改commit msg。

相关问题