【问题标题】:Is there a way to display a message to an end-user when they commit a file in Git?当他们在 Git 中提交文件时,有没有办法向最终用户显示消息?
【发布时间】:2016-09-08 18:36:45
【问题描述】:

当有人对我的 Git 存储库中的特定文件进行更改时,我想在用户通过 Git CLI 提交或推送时向他们显示一条消息。

场景:用户更改 crazycalculations.py,我想说,“嘿,我注意到您更改了 crazycalculations.py。您让会计部门的 John 检查您的更改吗?”。只是对最终用户的一个友好提醒,他们会在没有监督的情况下弄乱文件。

对我如何做到这一点有什么建议吗?

【问题讨论】:

    标签: git git-commit git-push


    【解决方案1】:

    是的,你可以用 git hooks 做到这一点。如果您导航到.git/hooks,您将看到可以在特定 git 事件上运行的 shell 代码示例。检查.git/hooks/pre-commit.sample会有一些你可以使用的示例代码。

    例如在.git/hooks/pre-commit的顶部:

    if git diff HEAD --name-only | grep -q "crazycalculations.py"; then
       echo "Are you sure you want to edit crazycalculations.py?"
       sleep 3
    fi
    

    文档:

    https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

    【讨论】:

    猜你喜欢
    • 2011-06-15
    • 2020-03-31
    • 2012-11-28
    • 2022-11-04
    • 2011-02-17
    • 2016-06-25
    • 2011-09-07
    • 2013-04-04
    • 2021-05-26
    相关资源
    最近更新 更多