git - 每次 git 提交后显示的自定义消息
问题描述
我们最近将我们的 git 存储库从 Gitlab 迁移到了 Bitbucket。
现在我想确保团队需要同时提交两个存储库,直到 Gitlab 退役。
仅仅告诉他们是不够的,因为人们可能会忘记推送到具有新存储库的 bitbucket,这可能会导致生产问题。
我想要做的是在用户尝试在 Gitlab 中进行任何提交(这是当前的存储库)时,在用户的机器上显示某种消息,例如“请同时推送到 BitBucket 存储库以避免冲突”,以便他每次他提交到 Gitlab 时都会被提醒。
有人可以告诉我如何在 git hooks 的帮助下实现这一目标。
解决方案
正如您提到的,您需要设置pre-receive hook
pre-receive hook
#!/bin/sh
# Output colors
red='\033[0;31m';
green='\033[0;32m';
yellow='\033[0;33m';
default='\033[0;m';
# personal touch :-)
echo "${red}"
echo " "
echo " |ZZzzz "
echo " | "
echo " | "
echo " |ZZzzz /^\ |ZZzzz "
echo " | |~~~| | "
echo " | |- -| / \ "
echo " /^\ |[]+ | |^^^| "
echo " |^^^^^^^| | +[]| | | "
echo " | +[]|/\/\/\/\^/\/\/\/\/|^^^^^^^| "
echo " |+[]+ |~~~~~~~~~~~~~~~~~~| +[]| "
echo " | | [] /^\ [] |+[]+ | "
echo " | +[]+| [] || || [] | +[]+| "
echo " |[]+ | || || |[]+ | "
echo " |_______|------------------|_______| "
echo " "
echo " "
echo " ${green} "
echo " You have to commit your code "
echo " To Gitlab as well !!!!! "
echo " "
echo " ${red} "
echo " P.S: Your code is bad. "
echo " Do not ever commit again "
echo " "
echo " "
echo "${default}"
exit 0;
- 您还可以为此添加客户端挂钩。
- 在 Bitbucket 中,钩子位于
<Bitbucket home>/data
对于 gitlab,您可以在此处阅读如何设置钩子以及它们的位置
https://docs.gitlab.com/ee/administration/custom_hooks.html您还可以使用插件来指定挂钩脚本的位置,但这些插件不再免费。