如何将 Git 的分支名称添加到提交消息中?
问题描述:
我需要一些有关 Bash 脚本的帮助,该脚本会自动将 git 的分支名称作为哈希添加到提交消息中.
I need some help with a Bash script that will automatically add the git's branch name as a hash in commit messages.
答
使用 prepare-commit-msg
或 commit-msg
githook.
您的 PROJECT/.git/hooks/
目录中已有示例.
There are examples already in your PROJECT/.git/hooks/
directory.
作为一项安全措施,您必须在要使用的每个存储库上手动启用此类挂钩.不过,您可以提交脚本并将其复制到所有克隆中到 .git/hooks/
目录中.
As a security measure, you will have to manually enable such a hook on each repository you wish to use it. Though, you can commit the script and copy it on all clones into the .git/hooks/
directory.