每次git提交后显示的自定义消息

时间:2018-04-24 19:07:34

标签: git githooks git-commit pre-commit-hook

我们最近将我们的git存储库从Gitlab迁移到了Bitbucket。

现在我想确保团队需要提交两个存储库,直到Gitlab退役。

通过告诉他们,这将是不够的,因为人们可能忘记推送到具有新存储库的bitbucket并且它可能导致生产问题。

我想要做的是获得某种消息,例如“请推送到BitBucket存储库以避免用户机器上的冲突”,当他试图在Gitlab中进行任何提交时(这是当前的回购)所以每当他投入Gitlab时都会提醒他。

有人可以告诉我如何在git hooks的帮助下实现这一目标。

1 个答案:

答案 0 :(得分:0)

正如您所提到的,您需要设置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

  • 您还可以使用插件指定挂钩脚本所在的位置,但这些插件不再是免费的。