git本地控制分支权限

来源:互联网 发布:jquery 1.11.1.min.js 编辑:程序博客网 时间:2024/06/11 01:14

1.新建commit-msg文件,文件内容如下

#!/bin/sh# 使用说明# 1.只有是自己的分支,才能提交,可以在myBranchs中设置,例子:myBranchs=("feature/lp_develop" "develop")# 2.如果不是自己的分支,想强制提交需要在提交信息中,需要提交信息的第一行为"force commit"# 3.myBranchs中的分支名称支持正则表达式,例子:myBranchs=("^feature/lp_")# 自己的分支(数组)myBranchs=("^feature/lp_")# 当前分支名称currentBranch=`git rev-parse --abbrev-ref HEAD`for i in ${myBranchs[@]}do   [[ $currentBranch =~ $i ]] && exit 0done# 提交信息第一行commitCntHead=`head -n 1 "$1"`if [[ $commitCntHead = "force commit" ]]then exit 0else echo "no authority commit to branch [ " $currentBranch "]" exit 1fi

2. 将些文件放到指定目录,例如  D:\git\hooks

3.使用命令:

 git config --global core.hooksPath /d/git/hooks

说明:git版本2.9以上才能设置全局变量

低版本只能将文件放到项目中的.git/hooks/文件夹中

4.使用说明

a.只有是自己的分支,才能提交,可以在myBranchs中设置,例子:myBranchs=("feature/lp_develop" "develop")

b.如果不是自己的分支,想强制提交需要在提交信息中,需要提交信息的第一行为"force commit"

5.具体钩子信息,详见https://git-scm.com/book/zh/v2/自定义-Git-Git-钩子
0 0
原创粉丝点击