zoukankan      html  css  js  c++  java
  • Git Hook

    背景:并行版本较多,合并至版本发布分支主分支时无法看出初始提交分支

    需求:系统开发人员执行git commit时,自动在commit-msg中补充当前所在分支名

    操作步骤:

    1、在子系统git仓库路径/.git/hooks下,将以下内容覆盖commit-msg.sample文件中

    #!/bin/sh
    #
    # An example hook script to check the commit log message.
    # Called by "git commit" with one argument, the name of the file
    # that has the commit message.  The hook should exit with non-zero
    # status after issuing an appropriate message if it wants to stop the
    # commit.  The hook is allowed to edit the commit message file.
    #
    # To enable this hook, rename this file to "commit-msg".
    
    branch_name=`git symbolic-ref --short -q HEAD`
    echo "${branch_name}"
    commit="<"${branch_name}">"$(cat $1)
    echo "$commit" > "$1"

    2、去掉文件名后缀.sample使其生效

    在git-bash中执行commit操作后,通过git log查看提交记录,此时提交信息已成功生效,显示内容为:<分支名>提交信息

  • 相关阅读:
    Java基础--day04
    Java基础--day03
    Java基础--day02
    高斯键盘设置指南
    博客园主题配置
    算法笔记--二分
    Test2反思
    树链剖分【模板】
    7.20关于莫队算法的一些初步理解
    分块(n根n复杂度)
  • 原文地址:https://www.cnblogs.com/fantastic-clouds/p/13530680.html
Copyright © 2011-2022 走看看