利用Git-hook自动配置不同仓库的用户信息

news/2025/5/24 1:57:58

微博上看到的 利用Git-hook自动配置不同仓库的用户信息,看了下平时也有这样的情况,不过没有在意过,现在看到了就要改啦!

看了下里面的参考链接:

  1. 让你的git拥有不同身份
  2. Automatic setup of user identity (user.email / user.name) on git clone

遇到的问题是我 我在windows 7 系统下paht路径识别的问题:
~/.git-templates 改成了 E:/Program Files/.git-templates

post-checkout的内容中涉及的 ~/.git-clone-init 改成了 "E:/Program Files/.git-templates/hooks/.git-clone-init" 记得加 " windows下没引号会引起转义错误,上全部代码!

post-checkout

#!/bin/bashfunction warn {echo -e "\n$1 Email and author not initialized in local config!"
}email="$(git config --local user.email)"
name="$(git config --local user.name)"if [[ $1 != "0000000000000000000000000000000000000000" || -n $email || -n $name ]]; thenexit 0
firemote="$([[ $(git remote | wc -l) -eq 1 ]] && git remote || git remote | grep "^origin$")"if [[ -z $remote ]]; thenwarn "Failed to detect remote."exit 0
fiurl="$(git config --local remote.${remote}.url)"if [[ ! -f "E:/Program Files/.git-templates/hooks/.git-clone-init" ]]; then
cat << INPUT > "E:/Program Files/.git-templates/hooks/.git-clone-init"
#!/bin/bash
case "\$url" in*@github.com:*    ) email=""; name="";;*//github.com/*   ) email=""; name="";;
esac
INPUTwarn "\nMissing file ~/.git-clone-init. Template created..."exit 0
fi
. "E:/Program Files/.git-templates/hooks/.git-clone-init"if [[ -z $name || -z $email ]]; thenwarn "Failed to detect identity using ~/.git-clone-init."exit 0
figit config --local user.email "$email"
git config --local user.name "$name"echo -e "\nIdentity set to $name <$email>"

.git-clone-init

case "$url" in*@github.com:* ) email="sumaolin@gmail.com";    name="sumaolin";;*//github.com/* ) email="sumaolin@gmail.com";    name="sumaolin";;*@git.kmtongji.com:* ) email="sumaolin@kongming-inc.com"; name="sumaolin";;*//git.kmtongji.com/* ) email="sumaolin@kongming-inc.com"; name="sumaolin";;*@git.coding.net:* ) email="sumaolin@qq.com"; name="sumaolin";;*//git.coding.net/* ) email="sumaolin@qq.com"; name="sumaolin";;
esac

不同的git地址匹配不同的账号,添加规则的时候注意正则的匹配规则!


https://dhexx.cn/news/show-4318481.html

相关文章

Python3(14):语法知识:找到数组中两数之和等于目标数对应的坐标

python3 语法知识&#xff1a;找到数组中两数之和等于目标数对应的坐标 给定一个整数数组 nums 和一个目标值 target&#xff0c;请你在该数组中找出和为目标值的那 两个 整数&#xff0c;并返回他们的数组下标。 你可以假设每种输入只会对应一个答案。 示例: 给定 nums [2…

Macaca iOS入门

2019独角兽企业重金招聘Python工程师标准>>> 一、Macaca环境 iwmbogon  ~  macaca doctor ************************************ * version 2.0.6 is outdate * * run: npm i -g macaca-cli2.0.9 * ************************************ More infor…

tomcat启动出现乱码

打开tomcat目录下apache-tomcat-9.0.26\conf\logging.properties 替换全文  encoding UTF-8  为  encoding GBK&#xff1b; restart

厂商“阅兵”:从2015年IFA看消费电子发展新趋势

作为全球三大电子消费品展会之一&#xff0c;IFA上的展品将引领着下半年全球消费电子产品的新趋势。 昨天是抗战胜利70周年纪念日&#xff0c;大家是不是都被北京“阅兵式”彻底征服了&#xff1f;今天&#xff0c;科技圈也有一场各大电子厂商的“大阅兵”&#xff1a;2015年柏…

搭建maven本地仓库,idea应用本地maven仓库

提环境&#xff1a; 安装好tomcat、maven、jdk、idea。 打开maven安装目录&#xff0c;在目录下新建  maven仓库文件夹(名子随便)&#xff1b; 打开conf\setting.xml 加入<localRepository></localRepository>;中间是你刚创建的maven本地仓库文件夹路径&#xff…

记录测试工作中,Mysql 数据库常用的一些 sql查询语句

记录测试工作中&#xff0c;常用的一些sql语句 Navicat连接测试Mysql数据库 1.查询项目名称为&#xff1a;HMFtest和业务类型为&#xff1a;传播-论坛的信息 多表查询(这里是三表)需要用到LEFT Join ON t1project 项目表 t1projectbusitype 项目类型表 t1probusitypedata…

简述ElasticSearch里面复杂关系数据的存储方式

2019独角兽企业重金招聘Python工程师标准>>> 在传统的数据库里面&#xff0c;对数据关系描述无外乎三种&#xff0c;一对一&#xff0c;一对多和多对多的关系&#xff0c;如果有关联关系的数据&#xff0c;通常我们在建表的时候会添加主外键来建立数据联系&#xff…

霍金去世 享年76岁

斯蒂芬威廉霍金&#xff08;Stephen William Hawking&#xff0c;1942年1月8日-2018年3月14日&#xff09;&#xff0c;ALS患者&#xff0c;英国著名物理学家和宇宙学家。肌肉萎缩性侧索硬化症患者&#xff0c;全身瘫痪&#xff0c;不能发音。霍金的主要研究领域是宇宙论和黑洞…

1.1 Jmeter应用进阶一:主要组件介绍(测试计划/线程组)

1.1 Jmeter应用进阶一&#xff1a;主要组件介绍 1、测试计划&#xff08;test plan&#xff09;&#xff1a;是使用Jmeter进行测试的起点&#xff0c;它是其他Jmeter测试元件的容器 2、线程组(Thread Group)&#xff1a;指一定数量的并发用户&#xff0c;它可以用来模拟并发用…

FTP服务器的搭建,记录一下走过的坑

在服务器上搭建了一个FTP服务器&#xff0c;开了防火墙&#xff0c;只放行了21端口&#xff0c;发现竟然客户端连接时候总是连接不上&#xff1b; google了一下&#xff0c;发现TCP传输需要至少两个端口&#xff0c;21端口只是处理命令的&#xff0c; 在21端口接受到命令后&…