利用Git-hook自动配置不同仓库的用户信息
微博上看到的 利用Git-hook自动配置不同仓库的用户信息,看了下平时也有这样的情况,不过没有在意过,现在看到了就要改啦!
看了下里面的参考链接:
遇到的问题是我 我在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/bash
function 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 ]]; then
exit 0
fi
remote="$([[ $(git remote | wc -l) -eq 1 ]] && git remote || git remote | grep "^origin$")"
if [[ -z $remote ]]; then
warn "Failed to detect remote."
exit 0
fi
url="$(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
INPUT
warn "\nMissing file ~/.git-clone-init. Template created..."
exit 0
fi
. "E:/Program Files/.git-templates/hooks/.git-clone-init"
if [[ -z $name || -z $email ]]; then
warn "Failed to detect identity using ~/.git-clone-init."
exit 0
fi
git 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地址匹配不同的账号,添加规则的时候注意正则的匹配规则!
设置完成后还要设置git hook生效:
git config --global init.templatedir ~/.git-templates
推荐阅读
本地开发环境中处理微信文章中图片防盗链的问题
前端黑科技-如何使用防盗链图片 通过iframe 来实现的 具体原理:防盗链图片,是被服务器判断了header中的referer的,但是如果referer=null,那就可以拿到图片了 感觉可以通过webServer 改写 http://mmbiz.qpic.cn...
苏茂林阅读 2.4k
一个开源vue网站博客,nuxt开源网站,前后端分离项目
开媛笔记,基于nuxt ssr首屏服务器端渲染 。用于分享、记录、交流和学习,希望可以帮助到小伙伴们。同时网站在不断更新,创造属于猿(媛)的世界 -$Bao Yalong ..Let's Go! [链接]
jigsaw赞 16阅读 8.4k评论 3
Git操作不规范,战友提刀来相见!
年终奖都没了,还要扣我绩效,门都没有,哈哈。这波骚Git操作我也是第一次用,担心闪了腰,所以不仅做了备份,也做了笔记,分享给大家。问题描述小A和我在同时开发一个功能模块,他在优化之前的代码逻辑,我在开...
王中阳Go赞 5阅读 1.8k评论 2
Git 入门与实践
Git 入门与实践推荐:猴子都能懂的 GIT 入门Git --everything-is-loca 官方文档Git 教程-廖雪峰Git 的使用方式有很多。图形化 —— 小乌龟(Tortoise Git )、命令行—— git bash、IDE 集成等 ......目录1. 基础配置...
RainBow赞 1阅读 2.2k
NB的Github项目,看到最后一个我惊呆了!
最近看到不少好玩的、实用的 Github 项目,就来给大家推荐一把。中国制霸生成器最近在朋友圈非常火的一个小网站,可以在线标记 居住、短居、游玩、出差、路过 标记后可生成图片进行社区分享,标记过的信息会记录...
艾小仙赞 5阅读 1.5k评论 1
git patch常用方法
针对指定的commit range生成patch,默认对每一个commit分别单独生成patch文件。patch文件按照commit的先后顺序从1开始编号。patch文件会生成到当前目录下。
黑暗森林赞 1阅读 13.1k评论 1
openSSH升级公钥失效Permission denied (publickey)解决方案
背景centos系统升级openSSH后,服务器上无法再拉取代码,报错如下:原因服务器重新安装SSH后公钥改变,需要重新安装ssh-keygen -t rsa -C "邮箱地址"生成公钥,删除gitlab原有公钥,但是git pull依然报错如下:依...
兰俊秋雨赞 1阅读 1.2k
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。